1. Output string length*******
echo strlen("hello");
2. Compare two strings
echo strcmp("ab","abc");
If two strings are the same, output 0, and if two strings are different, output -1. Note: case sensitive.
3. Compare two strings. Not case sensitive
echo strcasecmp("AB","ab");
If two strings are the same, output 0, and if two strings are different, output -1.
4. Convert the string to lowercase
echo strtolower("ABCD");
5. Convert the string to uppercase
echo strtoupper("abvcd");
6. Split string ******
$arr = explode("|","a|vdf|dfs|sdf");
var_dump($arr);
7. Splicing strings*******
$arr = explode("|","a|vdf|dfs|sdf");
echo implode("*",$arr);
Output:
8. Replace string *****
echo substr_replace("hellommworld","**",5,2);
Replace 2 characters starting from index 5 (replace the specified position)
9. Find and replace string ****
echo str_replace("l","*","hellommworld");
Find l, replace with *
10. Intercept string******
echo substr("hello",0,2);
echo substr("张三",0,3);
中文字符串,一个字符占三个索引
Output
11. Find the position where the string appears:
strrpos() -Find the position of the last occurrence of a string in another string (case sensitive)
strpos() -Find the position of the first occurrence of a string in another string (case sensitive)
stripos() -Find the first occurrence of a string in another string (not case sensitive)
strripos() -Find the position of the last occurrence of a string in another string (not case sensitive)