PHP Processing strings

Source: Internet
Author: User
1. Get the string length

$str'abc';$str1='中文';echo strlen($str),'
'
,strlen($str1); 输出结果:36

2. Find string

//查找字符串首次出现的位置$char'a';$str'abc';$bRet = strpos($str,$char);if($bRetfalse){    echo"$str 中不含有$char ";}else{    echo"$str 中含有$char ";}echo'
'

3. Replace string

//替换字符串str_replace()$str'Good morning';$str1 = str_replace('moring','afternoon',$str);echo$str'
'
$str1;输出结果:Good morningGood morning//替换字符串strtr()$str'上车,上课,上班,下车,下课,下班';$str1 = strtr($str,['上'=>'下','下'=>'上']);echo$str,'
'
,$str1;输出结果:上车,上课,上班,下车,下课,下班下车,下课,下班,上车,上课,上班

4. Intercepting strings

//截取字符串substr(),参数分别为目标字符串,起始位置,截取长度$str'East,west,home is best';echo$str,'
'
,substr($str,0,4);输出结果:East,west,home is bestEast

5. Splitting a string

//拆分字符串explode()$str'厨子, 戏子, 痞子';$arr = explode(',',$str);echo$str,'
'
;print_r($arr);输出结果:厨子, 戏子, 痞子Array ( [0] => 厨子 [1] => 戏子 [2] => 痞子 )

6. Merging arrays into strings

$arr=['0'=>'厨子','1'=>'戏子','2'=>'痞子'];$str=implode($arr,';');print_r($arr);echo'
'
;echo$str;输出结果:Array ( [0] => 厨子 [1] => 戏子 [2] => 痞子 ) 厨子;戏子;痞子

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the PHP processing string, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.