久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      php處理字符串的常用函數(shù)實例詳解

      php處理字符串的常用函數(shù)實例詳解

      php常用的處理字符串的函數(shù)實例總結(jié):

      /*常用的字符串輸出函數(shù) * * echo() 輸出字符串 * print() 輸出一個或多個字符串 * die() 輸出一條信息,并退出當(dāng)前腳本 * printf() 輸出格式化字符串 * sprintf() 把格式化的字符串寫入到一個變量中 * */  //ucfirst  //將字符串中的首字母轉(zhuǎn)換為大寫 $str="string"; echo ucfirst($str); echo "<hr><br/>";  //ucwords() //將字符串中的每個單詞的首字母大寫 $ucword="hello everyone!"; echo ucwords($ucword); echo "<hr><br/>";  //ltrim() rtrim() trim() //去除空格 $str="123 This is a test....."; echo ltrim($str,"0..9")."<br/>"; //去除左側(cè)的數(shù)字  echo rtrim($str,".")."<br/>"; echo trim($str,"0..9A..Z.")."<br/>"; //去除字符串兩端的大寫字母,數(shù)字還有. //HTML相關(guān)的字符串格式化函數(shù)  //nl2br() //將字符串中的n轉(zhuǎn)換為"<br/>" $str="this is n hello world"; echo nl2br($str).'<br/>';  //htmlspecialchars() //將html標記以字符的形式顯示,不進行解釋 $str="<b>hello world</b>"; echo $str."<br/>"; echo htmlspecialchars($str); echo "<hr><br/>";  //addcslashes //添加反斜線 $str=addcslashes("foo[]","A..z"); echo $str."<br/>"; echo addcslashes("zoo['.']",'A..z')."<br/>";  //convert_uuencode() //利用uudecode的方法對字符串進行編碼 $string="hello world"; $str= convert_uuencode($string); echo $str."<br/>"; echo convert_uudecode($str)."<br/>";  //html_entity_decode ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = 'UTF-8' ]] ) //與htmlentities方法相反,將進行編碼后的html字符轉(zhuǎn)換為瀏覽器能夠編譯的形式 $a="I want a bright <b>future</b>"; $b= htmlentities($a)."<br/>"; echo $b; echo html_entity_decode($b); echo "<hr><br/>";  //htmlspecialchars_decode ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 ] ) //與htmlspecialchars函數(shù)相反,將HTML實體轉(zhuǎn)換為字符 $c=htmlspecialchars($a); echo $c."<br/>"; echo htmlspecialchars_decode($c)."<br/>"; echo "<hr><br/>";  //lcfirst ( string $str ) //將字符串的首字符小寫 $str="Hello World"; // echo lcfirst($str)."<br/>";  //md5_file ( string $filename [, bool $raw_output = false ] ) //對文件進行md5加密 // $string="password"; $str=md5($string); if($str=="5f4dcc3b5aa765d61d8327deb882cf99"){  echo "The password is right <br/>"; }  //parse_str ( string $str [, array &$arr ] ) //將一個字符串進行解析,解析成變量和數(shù)組的形式 $str = "first=value&arr[]=foo+bar&arr[]=baz"; parse_str($str,$input); print_r($input); echo "<hr><br/>";  //string sha1_file ( string $filename [, bool $raw_output = false ] ) //計算文件的散列值 foreach(glob("C:/lamp/appache2/htdocs/*.php") as $ent){  if(is_dir($ent)){  continue;  }  echo $ent."(SHA1:".sha1_file($ent).")<br/>"; } echo "<hr><br/>";  //int similar_text ( string $first , string $second [, float &$percent ] ) //計算兩個字符串的相似度,通過引用方式傳遞第三個參數(shù),similar_text() 將 //計算相似程度百分數(shù)。 $string1="rogerzhalili"; $string2="zhangjieroger"; if(similar_text($string1,$string2,$percent)){  echo $string1." and ".$string2." has the similarity of:".$percent."<br/>"; } echo "<hr><br/>";  //string str_shuffle ( string $str ) //打亂一個字符串 $string="I want you to solve this problem"; echo str_shuffle($string)."<br/>";  //array str_split ( string $string [, int $split_length = 1 ] ) //按照指定的長度對字符串進行分割 $arr=str_split($string,3);  //str_word_count ( string $string [, int $format = 0 [, string $charlist ]] ) //統(tǒng)計字符串中單詞的數(shù)量 echo "<hr><br/>";  //int strripos ( string $haystack , string $needle [, int $offset = 0 ] ) //以不區(qū)分大小寫的方式查找指定字符串在目標字符串中最后一次出現(xiàn)的位置。與 strrpos() 不同,strripos() 不區(qū)分大小寫。 //offset用于指定從那個位置開始查找 $haystack='ababcd'; $needle='Ab'; echo "the last".$needle."postion is:".strripos($haystack,$needle)."<br/>"; echo strrpos($haystack,'ab'); echo "<hr><br/>";  //string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] ) //返回 haystack 字符串從 needle 第一次出現(xiàn)的位置開始到 haystack 結(jié)尾的字符串。 該函數(shù)區(qū)分大小寫。如果想要不區(qū)分大小寫,請使用 //stristr()。 $a="the First test"; $needle="Fi"; echo strstr($a,$needle)."<br/>"; if($c=strstr($a,"Fio")){  echo "find".$c."<br/>"; } else {  echo "not find the string!<br/>"; } echo "<hr><br/>";  //int substr_count ( string $haystack , string $needle [, int $offset = 0 [, int $length ]] ) //查找$needle子字符串在$haystack中出現(xiàn)的次數(shù),$needle區(qū)分大小寫 $hay="la la wa la wa wa lala"; echo substr_count($hay,"la")."<br>";  //int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG_PATTERN_ORDER [, int $offset = 0 ]]] ) //正則匹配,將匹配后的結(jié)果存放到$matches(如果指定了$matches的話) preg_match_all("/?(d3)?? (?(1) [-s] ) d{3}-d{4}/x", "Call 555-1212 or 1-800-555-1212", $phones); echo "<pre>"; print_r($phones); echo "</pre>"; echo "<hr><br/>";  //preg_replace ( mixed $pattern , mixed $replacement , mixed  $subject [, int $limit = -1 [, int &$count ]] ) //搜索subject中匹配pattern的部分, 以replacement進行替換. $string = 'April 15, 2003'; $pattern = '/(w+) (d+), (d+)/i'; $replacement = '${1}1,$3'; echo preg_replace($pattern,$replacement,$string); echo "<hr><br/>";  //array preg_split ( string $pattern , string $subject [, int $limit = -1 [, int $flags = 0 ]] ) //通過一個正則表達式分隔給定字符串. $str = 'string'; $chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY); print_r($chars);

      以上內(nèi)容僅供參考,若有錯誤請聯(lián)系指正。

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號