Common PHP string processing function usage example [convert, escape, intercept, compare, search, reverse, and cut]

Source: Internet
Author: User
This article mainly introduces the usage of common PHP string processing functions, and analyzes the case-sensitive conversion, escape, truncation, comparison, search, reverse, and cutting operations of php strings in the form of examples, for more information about common PHP string processing functions, see the examples in this article. We will share this with you for your reference. The details are as follows:

 '; Echo': '. strlen ($ s); echo'
'; // Upper case echo 'upper case:'. Ucfirst ($ s); echo'
'; Echo' uppercase letters of each word: '. Ucwords ($ s); echo'
'; Echo 'upper case:'. Strtoupper ($ s); echo'
'; Echo 'lower case:'. Strtolower ($ s); echo'
'; // Escape string function. before saving data to the database, use echo 'addslashes (); stripslashes ();'; $ s1 = '"a" B'; echo'
'; Echo addslashes ($ s1); echo'
'; // Capture echo substr ($ s, 4, 4); echo'
'; $ S2 = "hello world"; $ s3 = "test"; // comparison, returns 0 echo strcmp ($ s, $ s2) = 0? "Equal": "not equal"; echo'
'; Echo strcmp ($ s, $ s3) = 0? "Equal": "not equal"; echo'
'; // Find echo strpos ($ s, 'o'); echo'
'; Echo strrpos ($ s, 'o'); // Note: if not found, false = 0 is returned, therefore, you must use "=" to check if (XX = false); echo'
'; // Reverse echo strrev ($ s); echo'
'; // Cut $ arr = str_split ($ s); $ arr1 = str_split ($ s, 2); $ arr2 = explode ('', $ s ); var_dump ($ arr); var_dump ($ arr1); var_dump ($ arr2);?>

I hope this article will help you with PHP programming.

For more examples of common PHP string processing functions, see [conversion, escape, intercept, comparison, search, reverse, and cut] related articles!

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.