發新話題

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

《PHP》『字串函式庫』ob_implicit_flush 開啟或關閉固有的清除

ob_implicit_flush ---  開啟或關閉固有的清除

語法 : void ob_implicit_flush ([int flag])

說明 :

ob_implicit_flush( )將會開啟或關閉固有的(implicit)清除(如果沒有給予參數 flag,則它預設上是開啟),固有的清除將會導致在每次呼叫輸出後便會執行清除,如此一來將不再需要呼叫flush( )。

開啟固有的清除將會使輸出緩衝失去能力,如果有呼叫ob_end_flush( )則輸出緩衝現行的輸出將會被送出。

參考 :  flush( )  ob_start( )  ob_end_flush( )


TOP

《PHP》『字串函式庫』Ord 傳回字元的ASCII碼

Ord ---  傳回字元的ASCII碼

語法 : int ord (string string)

說明 :

傳回字串 string第一個字元的ASCII碼,此函式和chr( )互補。

Example :

<?php

   if (ord ($str) == 10) {

          echo "The first character of \$str is a line feed.\n";

   }

?>

參考 :  chr( )

TOP

《PHP》『字串函式庫』parse_str 剖析字串使它成為變數

parse_str ---  剖析字串使它成為變數

語法 : void parse_str (string str)

說明 :

剖析像是經由URL傳遞查詢字串的字串,並且設定變數在目前的範圍中。

Example :

<?php

   $str = "first=value&second[]=this+works&second[]=another";

   parse_str($str);

   echo $first;      /* prints "value" */

   echo $second[0];      /* prints "this works" */

   echo $second[1];      /* prints "another" */

?>

TOP

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

print ---  輸出字串

語法 : print (string arg)

說明 :

輸出參數 arg。

參考 : echo( )  printf( )  flush( )

TOP

《PHP》『字串函式庫』printf 輸出格式化字串

printf ---  輸出格式化字串

語法 : int printf (string format [, mixed args...])

說明 :

依照參數format的內容將字串格式化,格式化的內容請參考sprintf( )

參考 : print( )  sprintf( )  sscanf( )  fscanf( )  flush( )

TOP

《PHP》『字串函式庫』quoted_printable_decode 轉換引用可列出字串成為8-bit字串

quoted_printable_decode ---  轉換引用可列出字串成為8-bit字串

語法 : string quoted_printable_decode (string str)

說明 :

此函式傳回一個8-bit二進制字串,相當於將引用可列出(quoted printable)字串解碼。此函式類似於imap_qprint( ),不同處是此函式不需要IMAP模組。

TOP

《PHP》『字串函式庫』quotemeta 將特殊字元加上反斜線

quotemeta ---  將特殊字元加上反斜線

語法 : string quotemeta (string str)

說明 :

將字串 str中的下列字元前面加上反斜線。

. \\ + * ? [ ^ ] ( $ )
參考 : addslashes( )  htmlentities( )  htmlspecialchars( )  nl2br( )  stripslashes( )

TOP

《PHP》『字串函式庫』rtrim 移除多餘的空白

rtrim ---  移除多餘的空白

語法 : string rtrim (string str)

說明 :

傳回參數 str移除後面多餘的空白後的字串,包括新行(newlines)。此函式是chop( )的別名。

Example :

<?php

    $trimmed = rtrim ($line);

?>

參考 : trim( )  ltrim( )

TOP

《PHP》『字串函式庫』sscanf 依照格式剖析字串

sscanf ---  依照格式剖析字串

語法 : mixed sscanf (string str, string format [, string var1...])

說明 :

sscanf( )輸入的參數和printf( )類似,sscanf( )讀取字串 str,並且依照指定的格式 format來解釋它。如果只傳遞二個參數給此函式,則傳回剖析後的值將會是個陣列。

Example :

<?php

    // getting the serial number

    $serial = sscanf("SN/2350001","SN/%d");

    // and the date of manufacturing

    $mandate = "January 01 2000";

    list($month, $day, $year) = sscanf($mandate,"%s %d %d");

    echo "Item $serial was manufactured on: $year-".substr($month,0,3)."-$day\n";

?>

如果有傳遞非必需參數時,函式將會傳回分配值的數目,非必需參數必須依照關係傳遞。

Example :

<?php

    // get author info and generate DocBook entry

    $auth = "24\tLewis Carroll";

    $n = sscanf($auth,"%d\t%s %s", &$id, &$first, &$last);

    echo "<author id='$id'> <firstname>$first</firstname> <surname>$last</surname> </author>\n";

?>

參考 : fscanf( )  printf( )  sprintf( )

TOP

《PHP》『字串函式庫』setlocale 設定場所資訊

setlocale ---  設定場所資訊

語法 : string setlocale (string category, string locale)

說明 :

參數 category是個字串,指定函式的種類,會受到 locale設定的影響 :

LC_ALL - 下列全部的設定

LC_COLLATE - 字串比較 - 不是目前PHP的工具

LC_CTYPE -  字元分類和轉換,例如 : strtoupper( )

LC_MONETARY - 作為 localeconv( ) - 不是目前PHP的工具

LC_NUMERIC - 小數點的區分者

LC_TIME - 日期和時間格式,和strftime( )一起

如果參數 locale是空字串 " ",則 locale的名稱將會設成與上面categories相同名稱的環境變數值, 或是從 "LANG"。

如果參數 locale是 zero或 "0",則 locale的設定不會受到影響,只會傳回目前的設定值。

setlocale( )傳回一個新的現行場所(locale),如果平臺無法執行場所的機能,指定的場所不存在或是種類(category)名稱是無效時,則傳回false。一個無效的種類名稱會導致一個警告的訊息。

TOP

發新話題

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