發新話題

[分享] 《PHP》『字串函式庫』

《PHP》『字串函式庫』echo 輸出字串

echo ---  輸出字串

語法 : echo (string arg1, string [argn]...)

說明 :

輸出參數。

echo( )不是個真的函式(它是個語言結構),所以你並不必使用括弧。

Example :

<?php

    echo "Hello World";

    echo "This spans multiple lines. The newlines will be output as well";

    echo "This spans\nmultiple lines. The newlines will be\noutput as well.";

?>

注意 : 事實上,如果你想要傳遞一個以上的參數到此函式時,你不能使用括弧來將參數圍在裡面

參考 : print( )  printf( )  flush( )


TOP

《PHP》『字串函式庫』explode 切開字串

explode ---  切開字串

語法 : array explode (string separator, string string [, int limit])

說明 :

傳回一個字串的陣列,以參數 separator為界線將參數 string切開,如果有設定參數 limit,則傳回的陣列最多將會包含 limit個元素,而最後一個元素將會包含 string全部剩餘的部份。

Example :

<?php

   $pizza = "piece1 piece2 piece3 piece4 piece5 piece6";

   $pieces = explode (" ", $pizza);

?>

參考 : split( )  implode( )

TOP

《PHP》『字串函式庫』flush 清除輸出緩衝

flush ---  清除輸出緩衝

語法 : void flush(void);

說明 :

清除PHP的輸出緩衝。

TOP

『字串函式庫』get_html_translation_table 傳回使用的轉換表格

get_html_translation_table ---  傳回htmlspecialchars( )和htmlentities( )使用的轉換表格

語法 : string get_html_translation_table (int table)

說明 :

get_html_translation_table( )將會傳回htmlspecialchars( )和htmlentities( )內部使用的轉換表格,這裡有二個新的定義HTML_ENTITIES和HTMLSPECIALCHARS,這允許你去指定你想要的表格。

Example :

<?php

   $trans = get_html_translation_table (HTML_ENTITIES);

   $str = "Hallo & <Frau> & Kr鄝er";

   $encoded = strtr ($str, $trans);

?>

變數$encoded將會包含 : "Hallo & &lt;Frau&gt; & Krämer"

使用array_flip( )能改變轉化的方向

Example :

<?php

   $trans = array_flip ($trans);

   $original = strtr ($str, $trans);

?>

$original的內容將會是 : "Hallo & <Frau> & Kr鄝er"

注意 : 此函式是PHP4.0中新增的函式

參考 : htmlspecialchars( )  htmlentities( )  strtr( )  array_flip( )

TOP

『字串函式庫』get_meta_tags 從檔案取出所有meta標籤內容屬性並且傳回陣列

get_meta_tags ---  從檔案取出所有meta標籤內容屬性並且傳回陣列

語法 : array get_meta_tags (string filename [, int use_include_path])

說明 :

開啟檔案filename,並且一行一行的剖析<meta>標籤。

Example :

   <meta name="author" content="name">

   <meta name="tags" content="php3 documentation">

   </head> <!-- parsing stops here -->

name屬性的值會成為索引值,而content屬性的值會成為陣列的值,如此一來你便可以使用陣列函式庫來存取它的值,在name屬性的值的特殊字元會用"_"來替代,其餘的會轉換成小寫。

設定參數use_include_path為1,將會使PHP試著去開啟include_path中的檔案。

TOP

《PHP》『字串函式庫』hebrev 轉換希伯來語文字成為可看見的文字

hebrev ---  轉換希伯來語文字成為可看見的文字

語法 : string hebrev (string hebrew_text [, int max_chars_per_line])

說明 :

非必需的參數 max_chars_per_line指出每行最多輸出多少個字元,此函式會試著去避開破損的單字(breaking words)。

參考 : hebrevc( )

TOP

『字串函式庫』hebrevc 轉換希伯來語文字成為可看見的文字和新行的轉換

hebrevc ---  轉換希伯來語文字成為可看見的文字和新行的轉換

語法 : string hebrevc (string hebrew_text [, int max_chars_per_line])

說明 :

此函式和hebrev( )類似,不同的地方是它會轉換新行( \n)為 "<br>\n"非必需的參數 max_chars_per_line指出每行最多輸出多少個字元,此函式會試著去避開破損的單字(breaking words)。

參考 : hebrev( )

TOP

《PHP》『字串函式庫』htmlentities 轉換所有字元成為HTML實體

htmlentities ---  轉換所有字元成為HTML實體

語法 : string htmlentities (string string)

說明 :

此函式和htmlspecialchars( )相同,不同的是它會轉換所有HTML實體的字元。

參考 : htmlspecialchars( )  nl2br( )

TOP

《PHP》『字串函式庫』htmlspecialchars 轉換特殊字元成為HTML實體

htmlspecialchars ---  轉換特殊字元成為HTML實體

語法 : string htmlspecialchars (string string)

說明 :

在HTML中有些字元有著特殊的含義,如果要保留它們的意義則需要以HTML實體來表示它,此函式傳回轉換後的字串。

此函式用在預防使用者提供的文字中包含了HTML的標記,像是佈告欄或是訪客留言板這方面的應用。

目前轉換的字元有以下幾種:

'&' (and符號)轉換成 '&'

'"' (雙引號)轉換成 '"'

'<' (小於)轉換成 '&lt;'

'>' (大於)轉換成 '&gt;'

此函式不轉換上面以外的符號,要完整的實體轉換請使用htmlentities( )。

參考 : htmlentities( )  nl2br( )

TOP

《PHP》『字串函式庫』implode 將陣列的元素連結起來成為字串

implode ---  將陣列的元素連結起來成為字串

語法 : string implode (string glue, array pieces)

說明 :

以參數 glue將陣列 pieces的各個元素結合起來,此函式傳回字串來表示所有陣列的元素,字串的順序和陣列相同。

Example :

<?php

   $colon_separated = implode (":", $array);

?>

參考 : explode( )  join( )  split( )

TOP

發新話題

本站所有圖文均屬網友發表,僅代表作者的觀點與本站無關,如有侵權請通知版主會盡快刪除。