php method to replace the content between characters: first define a string; then find the position of the two specified strings; then use the substr function to delete the middle part; and finally replace the content.
Recommended: "PHP Video Tutorial"
It is best not to use regular expressions for this type of replacement, because The only thing you search for does not need to be used, and the replacement text is too large and the efficiency is too low.
The method is to find the positions of these two special strings, and then use substr to delete the middle part. Example code:
$str='....你要处理的字符串.....'; $s1='...开始字符串...'; $s2='...结束字符串...'; $i1=strpos($str,$s1);//开始位置 $i2=strpos($str,$s2);//结束位置 if ($i1!==false && $i2!==false)//找到 $str=substr($str,0,$i1-1) . substr($str,$i2+strlen($s2));
The above is the detailed content of How to replace content between characters in php. For more information, please follow other related articles on the PHP Chinese website!