php字串處理函數庫__函數

來源:互聯網
上載者:User

php字串處理函數庫

AddSlashes

字串加入斜線。

文法: string addslashes(string str);

傳回值: 字串

函數種類: 資料處理

本函數使需要讓資料庫處理的字串,引號的部份加上斜線,以供資料庫查詢 (query) 能順利運作。這些會被改的字元包括單引號 (')、雙引號 (")、反斜線 backslash (/) 以及Null 字元 NUL (the null byte)。

bin2hex

二進位轉成十六進位。

文法: string bin2hex(string str);

傳回值: 字串

函數種類: 資料處理

本函數讓二進位字串轉成十六進位字串。

補充:
josh@superfork.com (22-Jun-1999) 寫了一個函數,可將十六進位轉成二進位。

<?
function hex2bin($data) {
  $len = strlen($data);
  for($i=0;$i<$len;$i+=2) {
      $newdata .= pack("C",hexdec(substr($string,$i,2)));
  }
  return $newdata;
}
?>

Chop

去除連續空白。

文法: string chop(string str);

傳回值: 字串

函數種類: 資料處理

本函數將字串的連續空白清除。

<?
$trimmed = Chop($line);
?>

 

 

 

Chr

返回序數值的字元。

文法: string chr(int ascii);

傳回值: 字串

函數種類: 資料處理

本函數將字元的序數轉成 ASCII 的字元。本函數和 ord() 成對照。

<?
$str .= chr(27);
$str = sprintf("字串的結束字元是: %c", 27);
?>

chunk_split

將字串分成小段。

文法: string chunk_split(string string, int [chunklen] , string [end]);

傳回值: 字串

函數種類: 資料處理

本函數將字元變成小段供其它函數使用。例如,base64_encode。內定是參數 chunklen (76 個字元) 每隔 76 個字元插入 end ("/r/n")。返回新字串而不改動原字串。

將字串 $data 格式化成 MIME BASE64 格式

<?
$new_string = chunk_split(base64_encode($data));
?>

convert_cyr_string

轉換古斯拉夫字串成其它字串。

文法: string convert_cyr_string(string str, string from, string to);

傳回值: 字串

函數種類: 資料處理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.