* 1.strpos($str1,$str2, $offset) finds the position where $str1 first appears in $str1
* 2.strstr($str1, $str2), if $str2 is The substring of $str1, returns the substring, otherwise returns false
* If it is determined that $str2 is the substring of $str1, it is recommended to use strpos(), which is faster
* 3.str_replace ($str1, $str2, $str3, $num): substring replacement, $num is the number of replacements
* 4.substr_replace($str1,$str2,$str3,$start, $length): Replace the substring of the string
$str = 'www.php.cn';
//1.strpos($str,$needle, $offset)Find the first occurrence of the string
echo strpos($str, 'p'),'<br>'; //默认从头开始查找 echo strpos($str, 'p', 5),'<br>'; //从索引5开始查找
//2.strstr($str1 , $str2), if $str2 is a substring of $str1, return the substring, otherwise return false
echo strstr($str, 'php'),'<br>'; //返回子串及后面部分 echo strstr($str, 'php', true),'<br>'; //参数true,会返回子串前面部分 echo '<hr>';
//3.str_replace($str1, $str2, $str3, $num): substring Replace,
echo str_replace('www','http://www',$str), '<br>'; echo '<hr>';
//4.substr_replace($str1,$str2,$str3,$start, $length): Replace the substring of the string
//In $str, The 2 characters starting from the 5th index position are replaced with 'pppph'
echo substr_replace($str,'pppph', 5, 2);