標籤:
1.implode();
implode(separator,array): 傳回值(string)=array元素+separator。其中separator參數可選,但為向後相容,一般都帶上。
eg:
<?php
$arr = array(‘Hello‘,‘World!‘,‘I‘,‘love‘,‘Shanghai!‘);
echo implode(" ",$arr)."<br>";
echo implode("+",$arr)."<br>";
echo implode("-",$arr)."<br>";
echo implode("X",$arr);
?>
運行結果:
Hello World! I love Shanghai!
Hello+World!+I+love+Shanghai!
Hello-World!-I-love-Shanghai!
HelloXWorld!XIXloveXShanghai!
2.explode()
explode(separator,str,limit):傳回值(Array)。
Notice:當limit>0,Array.length=limit;
當limit<0時,Array.length=str.length-1;
當limit=0時,Array.length=1.
eg:
<?php
$str = ‘one,two,three,four‘;
// 零 limit
print_r(explode(‘,‘,$str,0));
// 正的 limit
print_r(explode(‘,‘,$str,2));
// 負的 limit
print_r(explode(‘,‘,$str,-1));
?>
運行結果:
Array ( [0] => one,two,three,four )
Array ( [0] => one [1] => two,three,four )
Array ( [0] => one [1] => two [2] => three )
3.get_include_path()
擷取當前預設目錄
4.set_include_path()
set_include_path(new_inlcude_path):配置新的路徑,使得通過include()函數可以直接存取該路徑下的檔案,簡化了目錄計算。
eg:
<?php
set_include_path("Website/");
include("test1.php");
include("test2.php");
include("test3.php");
require("test4.php");
require("test5.php");
?>
5.ob_start()
ob是output buffer的簡稱。ob_start()用來啟用伺服器緩衝區。當該函數被調用,除頭資訊外其餘資訊均不會輸出。
若要輸出,則使用相應Flush或bo_end_flush()函數。
PHP常用函數