PHP實現刪除字符串中任何字符的函數


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); 

輸出為:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM