The 1.strpos () function is used to find a character or a specified text within a string.
If a match is found in the string, the function returns the first matching character position. If no match is found, FALSE is returned .
<?phpecho Strpos ("Hello world!", "World");? > Return: 6
2. The strlen () function returns the length (number of characters) of the string.
<?phpecho strlen ("Hello world!");? > Return: 12
3. The Str_split () function splits the string into an array.
<?php//three a group into an array of Print_r (Str_split ("Hello", 3)); >
Array ([0] = Hel [1] = lo)
4.explode ()
<?PHP$STR = "Hello World W3cschool";p rint_r (Explode ("", $str));? >
Results:
Array ( [0] = Hello [1] = [2] = = W3cschool)
5. Replace the character "world" (case insensitive) in the string "Hello world!" with "Peter": Str_ireplace () "Case insensitive"
Replace the character "world" (case-insensitive) in the string "Hello world!" with "Peter": Str_replace () "Case Sensitive"
<?phpecho Str_replace ("World", "Peter", "Hello world!");? >
6. substr (string,start,length) Start: Index
<?phpecho substr ("Hello World", 6);? >
Output: World
7.strstr (string,search,before_search)------stristr (string,search,before_search) is case insensitive
| String |
Necessary. Specifies the string to be searched. |
| Search |
Necessary. Specifies the string to search for. If the parameter is a number, the character that matches the ASCII value of the number is searched. |
| Before_search |
Optional. A Boolean value with the default value of "false". If set to "true", it returns the string portion of the first occurrence of the search parameter. |
<?phpecho strstr ("Hello world!", "World");? > Output: World
The third one if true indicates that all values before the string are returned otherwise the found string is returned
<?phpecho strstr ("Hello world!", "World", true);? > Output: Hellow
8. Replacing strings
<?phpecho substr_replace (' abcdef ', ' # # # ', 1);//Output a## #echo substr_replace (' abcdef ', ' # # # ', 1, 2);//Output a## #defecho Substr_replace (' abcdef ', ' # # # ',-3, 2);//Output abc## #fecho substr_replace (' abcdef ', ' # # # ', 1,-2);//output a## #ef?>
PHP string processing