Strstr () in php string function learning. Strstr () for php string function Learning. the code for copying string strstr is as follows: php * definition and usage of strstr () the function is used to search for the first time that a string appears in another string. strstr () for php string function Learning. strstr
The code is as follows:
<? Php
/*
Definition and usage
The strstr () function searches for the first occurrence of a string in another string.
This function returns the rest of the string (from the matching point ). If the searched string is not found, false is returned.
Syntax
String strstr (string, search)
Parameter description
String is required. Specifies the string to be searched.
Search is required. Specifies the string to be searched. If this parameter is a number, search for characters that match the ASCII value of the number
Tips and comments
Note: This function is binary secure.
Note: This function is case sensitive. Use stristr () to perform case-insensitive searches ().
If you only want to determine whether the needle exists in the haystack, use strpos () functions that are faster and consume less memory.
*/
$ Str = ". Specified string to be searched ";
$ S = "";
Echo strstr ($ str, $ s )."
";
Echo mb_strstr ($ str, $ s, 'utf-8 ')."
";
Echo mb_strstr ($ str, $ s, true, 'utf-8 ')."
";
Echo mb_strstr ($ str, $ s, false, 'utf-8 ')."
";
/*
Definition and usage
The strrchr () function finds the position of the last occurrence of a string in another string, and returns all characters from this position to the end of the string.
Otherwise, false is returned.
Syntax
Strrchr (string, char)
Parameter description
String is required. Specifies the string to be searched.
Char is required. Specifies the characters to be searched. If this parameter is a number, search for characters that match the ASCII value of the number.
*/
Echo strrchr ($ str, $ s )."
";
Echo mb_strrchr ($ str, $ s, 'utf-8 ')."
";
Echo mb_strrchr ($ str, $ s, true, 'utf-8 ')."
";
Echo mb_strrchr ($ str, $ s, false, 'utf-8 ')."
";
$ Str = "Hello world! Hello world! ";
$ S = "world ";
Echo strrchr ($ str, $ s )."
";
Echo mb_strrchr ($ str, $ s, 'utf-8 ')."
";
Echo mb_strrchr ($ str, $ s, true, 'utf-8 ')."
";
Echo mb_strrchr ($ str, $ s, false, 'utf-8 ')."
";
/*
Definition and usage
The strtr () function converts special characters in a string.
Syntax
Strtr (string, from,)
Or
Strtr (string, array)
Parameter description
String1 is required. Specifies the string to be converted.
From is required (unless an array is used ). Specifies the character to be changed.
To is required (unless an array is used ). Specifies the character to be changed.
Array is required (unless from and to are used ). An array where the key is the original character and the value is the target character.
Description
If the length of from and to is different, the format is the shortest length.
*/
Echo strtr ("Hilla Warld", "ia", "eo ")."
";
$ Arr = array ("Hello" => "Hi", "world" => "earth ");
Echo strtr ("Hello world", $ arr )."
";
Echo strtr ("If omitted, internal character encoding is used", "internal", "external ")."
";
$ Arr = array ("if" => "if", "then" => "then ");
Echo strtr ("If omitted, internal character encoding is used", $ arr )."
";
?>
Substring (), string strstr code: php/* definition and usage strstr () function to search for the first appearance of a string in another string...