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!