Common PHP string processing function usage example [conversion, escape, truncation, comparison, search, reverse, CUT], example escape

Source: Internet
Author: User

Common PHP string processing function usage example [conversion, escape, truncation, comparison, search, reverse, CUT], example escape

This article analyzes common PHP string processing function usage. We will share this with you for your reference. The details are as follows:

<? Php $ s = "hello world"; // sort out echo 'trim (); ltrim (); rtrim () '; echo' <br/> '; echo'. The length is: '. strlen ($ s); echo '<br/>'; // upper case echo 'Upper case :'. ucfirst ($ s); echo '<br/>'; echo 'Upper-case letters of each word :'. ucwords ($ s); echo '<br/>'; echo 'Upper case :'. strtoupper ($ s); echo '<br/>'; echo 'lower case :'. strtolower ($ s); echo '<br/>'; // escape string function. Before saving data to the database, use echo 'addslashes (); stripslashes ();'; $ s1 = '"a" B'; echo '<br/>'; echo addslashes ($ s1); echo '<br/> '; // Capture echo substr ($ s, 4, 4); echo' <br/> '; $ s2 = "hello world"; $ s3 = "test "; // compare, return 0 echo strcmp ($ s, $ s2) = 0? "Equal": "Unequal"; echo '<br/>'; echo strcmp ($ s, $ s3) = 0? "Equal": "Unequal"; echo '<br/>'; // find echo strpos ($ s, 'O'); echo '<br/> '; echo strrpos ($ s, 'O'); // Note: If not found, false = 0 is returned, therefore, use "=" to check if (XX = false); echo '<br/>'; // reverse echo strrev ($ s ); echo '<br/>'; // cut $ arr = str_split ($ s); $ arr1 = str_split ($ s, 2); $ arr2 = explode ('', $ s); var_dump ($ arr); var_dump ($ arr1); var_dump ($ arr2);?>

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.