Php string processing function tutorial-PHP source code

Source: Internet
Author: User
Tags chop
Ec (2); truncate the string mb_substr ($ str, star, count, encode); obtain the string length mb_strlen (); keep the complete text in textarea text by carriage return and line break str_replace (chr (10), & quot; & lt; br & gt; & quot;, $ textarea ); return the corresponding letter echo & quot; ascii 66 Based on ascii: script ec (2); script

// Truncate the string
Mb_substr ($ str, star, count, encode );
// Obtain the string length
Mb_strlen ();
// Completely retained in the text of textarea.
Str_replace (chr (10 ),"
", $ Textarea );


// Return corresponding letters based on ascii
Echo "the letter with ascii 66 is:". chr (66 )."
";

// Chop removes consecutive spaces and spaces in the string
$ Str = "he llo wo rd"; echo "s :";
Echo "s:". chop ($ str). "w ";

// Explode splits the string by a character and returns an array
$ Str = "green, red, yellow, white ";
$ Arr = explode ("", $ str); echo "the split array is :";
Print_r ($ arr );

// Implode concatenates an array into a string based on a specific character
$ Arr = array ("a", "B", "c", "d ");
$ Str = implode ('/', $ arr );
Echo"
The concatenated string is: ". $ str;

// Print
Print ("print method ");
Echo "formatting printf:
";
Printf ("% f %", 2, "d ");

// Case-insensitive comparison string
Echo "Case Insensitive:". strcasecmp ("hello word", "hello word ");
// Case sensitive
Echo "case sensitive:". strcmp ("hello word", "hello word ");

// Search for strings
Echo "the search result is:". strchr ("hello word", "hello ");
// String Length
Echo "str length:". strlen ("hello word ");

// Repeat the string several times
Echo "repeat the string several times:". str_repeat ("ws", 3 );

// Sort strings in reverse order
Echo "zifuchuandaoxu:". strrev ("zifuchuandaoxu ");

// Converts strings in upper case and lower case
// Strtolower ();
// Strtoupper ();
// String replacement,
Echo "The replaced string is:". str_replace ("B", "*", "aaaaaaabbbbbccccc ");
// Cut string
Echo "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.