(Practical) summary of common php string function instances [convert, replace, compute, intercept, and encrypt]

Source: Internet
Author: User
This example summarizes common String functions in php. For your reference, this article provides an example of the String function commonly used in php. We will share this with you for your reference. The details are as follows:

Nl2br

Function: convert the line break

 

Rtrim

Function: clear the white space on the right.

  "; $ Result = rtrim ($ str); echo strlen ($ result);/** result 1411 */

Strip_tags

Function: clear html and php tags in a string.

  

Strtolower and strtoupper

Function: converts the string to lowercase.

   "; $ Result = strtoupper ($ str); echo $ result;/** result hello world! Hello world! */

Trim

Function: removes spaces at the beginning and end.

   "; Echo $ result ."
"; Echo strlen ($ str )."
"; Echo strlen ($ result);/** The result is Hello World! Hello World! 1612 */

Str_ireplace

Function: replace

   "; Echo $ result;/** result zhang sanli san */

Str_repeat

Function: repeat a string multiple times.

   "; Echo $ result;/** result Hello jiqing! Hello jiqing! Hello jiqing! Hello jiqing! Hello jiqing! */

Str_replace

Function: case-sensitive replacement

   "; Echo $ result1 ."
"; Echo $ result2 ."
";/** Result hello jiqing! Hi jiqing! Hello jiqing! */

Str_word_count

Function: returns the number of words in a string.

   "; Echo $ result1 ."
"; Print_r ($ result2);/** The result is hello jiqing! 3 Array ([0] => hello [1] => jiqing [2] => )*/

Strlen

Function: returns the string length.

   

Substr_count

Function: calculates the number of strings in another string.

    

Substr_replace

Function: start from a specified position.

     "; $ Result = substr_replace ($ str," zhangsan ",); // replace the string from a certain position with echo $ result;/** The result is hello zhangsanhello zhangsan, hello jim! */

Substr

Function: Gets a substring.

     "; $ Result = substr ($ str, 0,-1); // Get the echo $ result except the last string starting from 0th ."
"; $ Result = substr ($ str, 2,-1); // Get the echo $ result except the last string starting from 2nd ."
"; $ Result = substr ($ str,-3,-1); // obtains the echo $ result string except the last one starting from-3 ."
"; $ Result = substr ($ str,-3, 1); // Get the echo $ result except the last string from-3 ."
";/** Result aabcdecdeded */

Implode

Function: converts an array to a string.

     

Md5

Function: performs md5 encryption on strings.

      

The above is a summary of common php string function examples (conversion, replacement, calculation, interception, encryption). For more information, see PHP Chinese network (www.php1.cn )!

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.