Four. format string function Number_format ()
$str"123445677";$strl = number_format($str);$str2 = number_format($str,2);$str3 = number_format($str,2,",",'.');echo$str."
";echo$strl."
";echo$str2."
";echo$str3."
";
结果如下所示,number_format(str)表示在千分位上加,隔开。number_format(str,2)表示留两位小数点。number_format($str,2,",",".")把“,”替换成“.”。
Five. Divide the string into the array function/emplode (). Concatenate the array into a string function implode ().
$str"你好@php编程@每天进步一点";$tem = explode('@',$str);$teml = explode('@',$str,2);print_r($tem);echo"
";print_r($teml);
Results: Explode (ch,str,limit). CH represents the split character of the split string. STR represents a String. Limit is optional, indicating that you want to split several times, by default, all.
$arrayarray("hello","php编程","每天进步一点");$str = implode(",",$array);print_r($str);
结果如 。implode(separator,array)。 separator表示已什么来合成字符串。可选的。默认为空。array表示要合并成字符串的数组
Six. Intercept string/substr (Str,separator)
$str"hello,php编程";$strm = substr($str,3);$strl = substr($str,-3);echo$strm."
";echo$strl;
substr(str,separator)。str指的是所要截取的字符串。separtor表示从哪里开始截取。正数代表从左开始截取。负数代表从右开始截取。这里3个字符代表一个汉字。(utf-8里是三个字符一个汉字,gb2312里是二个字符一个汉字。)
The above describes the PHP string function (2), including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.