欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php常用字符串處理函數(shù)實(shí)例分析

 更新時(shí)間:2014年11月22日 14:36:59   投稿:shichen2014  
這篇文章主要介紹了php常用字符串處理函數(shù),以實(shí)例形式分析了chop()、get_html_translation_table()、htmlentities()及htmlspecialchars()等函數(shù)的具體用法,對(duì)于PHP的學(xué)習(xí)有著一定的學(xué)習(xí)與借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了php常用字符串處理函數(shù)。分享給大家供大家參考。具體分析如下:

這里只提供幾個(gè)簡(jiǎn)單常用的函數(shù):
chop執(zhí)行去除空格處理,get_html_translation_table返回轉(zhuǎn)化列表到變量,定義包括HTML編碼的字符串htmlentities,htmlspecialchars_decode 定義包含HTML特殊字符的字符串,nl2br quotemeta rtrim等.

定義和用法:chop() 函數(shù)從字符串的末端開(kāi)始刪除空白字符或其他預(yù)定義字符,該函數(shù)的 rtrim() 函數(shù)的別名.

語(yǔ)法:chop(string,charlist),代碼如下:

復(fù)制代碼 代碼如下:
$str="i'm a   teacher  ";          //定義字符串
$result=chop($str);           //執(zhí)行去除空格處理
echo $result;            //輸出結(jié)果

定義和用法:get_html_translation_table() 函數(shù)返回被 htmlentities() 和 htmlspecialchars() 函數(shù)使用的翻譯表.

語(yǔ)法:get_html_translation_table(function,quotestyle),代碼如下:

復(fù)制代碼 代碼如下:

$trans=get_html_translation_table(html_entities);    //返回轉(zhuǎn)化列表到變量
print_r($trans);            //輸出轉(zhuǎn)換表
$str="hallo & <frau> & krmer";         //定義字符串
$encoded=strtr($str,$trans);         //查找字符
echo $encoded;           //輸出結(jié)果
//
 
$str="a 'quote' is <b>bold</b>";       //定義包括html編碼的字符串
echo htmlentities($str);        //輸出經(jīng)過(guò)處理的字符串
echo htmlentities($str, ent_quotes);     //加上可選參數(shù)后的輸出結(jié)果
 
//
$str='<p>this -&gt; "</p>';        //定義包含html特殊字符的字符串
echo htmlspecialchars_decode($str);     //輸出轉(zhuǎn)換后的內(nèi)容
echo "<br>";
echo htmlspecialchars_decode($str,ent_noquotes);  //不對(duì)引號(hào)進(jìn)行編碼的輸出結(jié)果
 
//
 
$str="cat isn't n dog";      //定義包含換行符的字符串
$result=nl2br($str);       //執(zhí)行轉(zhuǎn)換操作
echo $result;        //輸出轉(zhuǎn)換后的結(jié)果
 
//
 
$str="hello world.(can you hear me?)";      //定義包含元字符的字符串
$result=quotemeta($str);         //執(zhí)行轉(zhuǎn)換操作
echo $result;           //輸出轉(zhuǎn)換后的結(jié)果
//
 
$str="hello world  ";          //定義末尾有空格的字符串
$result=rtrim($str);          //執(zhí)行轉(zhuǎn)換操作
echo $result;           //輸出轉(zhuǎn)換后的結(jié)果

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論