PHP String Functions (2)

Source: Internet
Author: User
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.

  • 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.