PHP字符串函數示例

1、chunk_split()函數
  把字符串切割成更小的部分
  語法
  chunk_split(string,length,end);
  代碼示例
  php
  str=holleword;  echochunksplit(str=”holleword”;   echochunk_split(str,2,’,’).”
  “;
  echochunk_split(str,3,,).  ;  ?>  2explode()  使    explode(str,3,’,’).”   “;   ?>   2、explode()函數   使用一個字符串切割另一個字符串,並回來由字符串組成的數組   語法   explode(“切割符”,string,limit)
  代碼示例
  php
  str=one,two,three,apple,blue;  printr(explode(,,str=”one,two,three,apple,blue”;   print_r(explode(“,”,str,2));
  print_r(explode(“t”,str,5));  3implode()      implode(array);    php  str,5));   3、implode()函數   回來一個由數組元素組合成的字符串   語法   implode(“元素之間放置的內容”,array);   代碼示例   php   str=array(‘holle’,’jack’,’welcome’,’to’,’city’);
  echoimplode(“”,str);  ?>  4md5()  md5    MD5string);    php  str);   ?>   4、md5()函數   md5加密   語法   MD5(string);   代碼示例   php   str=”helloworld”;
  echomd5(KaTeX parse error: Expected 'EOF', got '#' at position 12: str);   ?>c#̲獲取文字全拼音   5、str…str=”helloPHP”;
  echostrlen(str);  ?>  6strrepeat()      strrepeat(string,int);    php  str);   ?>   6、str_repeat()函數   回來重複後的字符串   語法   str_repeat(string,int);   代碼示例   php   str=”-+-/”;
  echostr_repeat(str,5);  ?>  7strreplace()      strreplace(str,5);   ?>   7、str_replace()函數   該函數回來替換後的數組或者字符串   語法   str_replace(search,replace,string,int)    php  replace,string,int)   代碼示例   php   str=”helloworld”;
  str1=strreplace(l,,str1=str_replace(“l”,””,str,count);  echocount);   echocount;
  ?>
  8、substr_count()函數
  統考某個子串的呈現的頻率
  語法
  substr_count(str,str,needel,start,start,length)
  代碼示例
  php
  str=helloworld;  echosubstrcount(str=”helloworld”;   echosubstr_count(str,’o’),’
  ‘;
  ?>
  9、str_pad()
  將字符串填充到指定長度
  語法
  str_pad(string,length,”填充字符”)
  代碼示例
  php
  echostr_pad(‘hello’,10,’*+’);
  ?>
  10、wordwrap()函數
  打斷字符串爲指定數量的字串
  語法
  wordwrap(stringstr[,intstr[,intwidth=75[,stringKaTeX parse error: Undefined control sequence: \n at position 8: break=“\̲n̲”[,boolcut=FALSE]]])
  代碼示例
  php
  str=helloworld;  echowordwrap(str=”helloworld”;   echowordwrap(str,5,”——”,true);
  ?>
  11、ucfirst()
  將字符串的首字母轉換爲大寫
  語法
  ucfirst(string)
  代碼示例
  php
  str=helloworld;  echoucfirst(str=”helloworld”;   echoucfirst(str);
  ?>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章