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 )!