Home >Backend Development >PHP Problem >How to delete any character in a string in php
php method to delete any character in a string
function delStr($start, $end, $orgenStr) { //读取要删除字符位置的前一部分字符串,并赋值给$temp //strpos读取字符第一次出现的位置 //substr读取指定开始与结束位置的子字符串 //echo $before."—". $last; $temp=$orgenStr; while(strpos($temp, $start) && strpos($temp, $end)){ $temp=substr($temp, 0, strpos($temp, $start)).substr($temp,strpos($temp, $end)+strlen($end));; //读取要删除字符位置的后一部分字符串,然后将前后部分连接,并赋值给$temp //返回最后是字符串 } return $temp; } //应用实例 $a="aaaa12345678bbbbtttttttttttttttttttttaaaa12345678bbbb kkkkkkkkkkkkaaaa12345678bbbbttttttttttttttttttttt"; $b="1234"; $c="5678"; echo delStr($b,$c,$a);
Output result:
Recommended: "PHP Tutorial"
The above is the detailed content of How to delete any character in a string in php. For more information, please follow other related articles on the PHP Chinese website!