PHP string processing functions Daquan Tutorial

Source: Internet
Author: User
Tags chop explode

Intercepting strings
Mb_substr ($str, Star,count,encode);
Get string length
Mb_strlen ();
Carriage return wrap complete in textarea text
Str_replace (CHR), "<br/>", $textarea);


Return the corresponding letter based on ASCII
echo "ASCII is a 66 letter:". Chr (66). " <br> ";

Chop to remove contiguous spaces and whitespace in a string
$str = "he llo Wo Rd"; echo "s:";
echo "s:". Chop ($STR). W ";

Explode to return an array by a character-splitting string
$str = "Green,red,yellow,white";
$arr =explode ("", $str); the array after the echo is: ";
Print_r ($arr);

Implode the array into a string by a character
$arr =array ("A", "B", "C", "D");
$str =implode ('/', $arr);
echo "<br> string is:". $str;

Printing print
Print ("Printing method prints");
echo "Format print printf:<br>";
printf ("%f%", 2, "D");

Case-insensitive comparison strings
Echo is case-insensitive:. strcasecmp ("Hello word", "Hello word");
Case sensitive
echo "case-sensitive:". strcmp ("Hello word", "Hello word");

Find string
echo "The result of the lookup is:". STRCHR ("Hello word", "hello");
String length
echo "str length:". strlen ("Hello word");

Repeat the string several times Str_repeat
echo "repeats the string several times:". Str_repeat ("WS", 3);

Arrange strings in reverse order
echo "Zifuchuandaoxu:". Strrev ("Zifuchuandaoxu");

Capitalize the string and convert it to lowercase
Strtolower ();
Strtoupper ();
String substitution,
echo "The replaced string is:". Str_replace ("B", "*", "AAAAABBBBBCCCCC");
Cutting string
echo "After the cut string is:". substr ("Hello word", 2, 3);

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.