1function delStr($start, $end, $orgenStr) 2{ 3 //读取要删除字符位置的前一部分字符串,并赋值给$temp 4 //strpos读取字符第一次出现的位置 5 //substr读取指定开始与结束位置的子字符串 6 //echo $before."—". $last; 7 $temp=$orgenStr; 8 while(strpos($temp, $start) && strpos($temp, $end)){ 9 $temp=substr($temp, 0, strpos($temp, $start)).substr($temp,strpos($temp, $end)+strlen($end));; 10 //读取要删除字符位置的后一部分字符串,然后将前后部分连接,并赋值给$temp 11 //返回最后是字符串 12 } 13 return $temp; 14} 15//应用实例 16$a="aaaa12345678bbbbtttttttttttttttttttttaaaa12345678bbbb 17kkkkkkkkkkkkaaaa12345678bbbbttttttttttttttttttttt"; 18$b="1234"; 19$c="5678"; 20echo delStr($b,$c,$a);
输出为:
