2013-06-27 / JSN / 0 Comments / 34 views
使用pagination class的時候
若沒有使用參數 $config[‘num_tag_open’] 與 $config[‘num_tag_close’]
會造成輸出的字串有空白( )字元佔位…..
導致分頁數字無法完美對齊。
如:
|
; html-script: false ]<div class="pagination_list"> <a href="http://">1</a> <span class="current">2</span> <a href="http://">3</a> <a href="http://">4</a> </div> |
所以指定num_tag_open與num_tag_close隨便的標籤即可解決。
|
; html-script: false ] /* 自訂分頁數字連結 */ $config['num_tag_open'] = '<span>'; $config['num_tag_close'] = '</span>'; |
2013-05-31 / JSN / 0 Comments / 106 views
這東西挺好用的!
http://simplehtmldom.sourceforge.net/
用來抓取html元素
就像PHP內建抓取xml樹狀元素一樣
不過尋找標籤的用法類似jQ的selector,下面是官方範例
|
// Create DOM from URL or file $html = file_get_html('http://www.google.com/'); // Find all images // find()裡面就如同jQ的選擇器,尋找<img>就寫img也可以組合class + html或其他標籤動作 foreach($html->find('img') as $element) echo $element->src . '<br>'; // Find all links foreach($html->find('a') as $element) echo $element->href . '<br>'; |
2013-04-03 / JSN / 0 Comments / 33 views
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
<?php session_start(); $_SESSION['test'] = 1; function __autoload($className) { $className = $className . '.php'; include_once($className); echo "因為 $className 不存在,在掛掉之前執行了加載了, 如果有成功就往下執行,反之則會終止程式 <br>"; } $testclass1 = new testclass1(); $testclass2 = new testclass2(); echo "END"; ?> 輸出會是 因為 testclass1.php 不存在,在掛掉之前執行了加載了, 如果有成功就往下執行,反之則會終止程式 因為 testclass2.php 不存在,在掛掉之前執行了加載了, 如果有成功就往下執行,反之則會終止程式 END 用法就在於,當class不存在時,會自動呼叫__autoload(), 如果到__autoload()結束前都沒辦法找到class來源,那就會終止執行(die;)。 |
2013-03-04 / JSN / 0 Comments / 1,248 views
[php]
<?php
$a = new ArrayObject(array(), ArrayObject::STD_PROP_LIST);
$a->first = "001";
$a->second->one = "002";
$a->second->two = "003";
/*
* 若要將 物件 轉換為 陣列, 看了一下網路的寫法似乎都沒有官方的做法。
* 突然想到若用json_encode與json_decode就能簡易的轉換!
* 速度沒測過,不知道效能囉
*/
$json = json_encode($a);
$json = json_decode($json, true);
echo $json[‘second’][‘two’]; //得到003
?>
[/php]
2013-03-04 / JSN / 0 Comments / 570 views
[php]
<?
/*
* 使用 ArrayObject(array(), ArrayObject::STD_PROP_LIST);
* 把物件當陣列使用
*/
$a = new ArrayObject(array(), ArrayObject::STD_PROP_LIST);
$a->first = "001";
$a->second->one = "002";
$a->second->two = "003";
echo $a->first;
?>
[/php]