PHP头条
热点:

php的str_replace()函数使用正则解决方法


php的str_replace() 函数使用正则
字符串如下:
“http:\/\/www.sina.com\/music1\/23412455.mp3?time=2234523&type=mp3”
“http:\/\/www.sina.com\/music2\/4325243.mp3?time=2234523&type=mp3”
“http:\/\/www.sina.com\/music3\/346553.mp3?time=2234523&type=mp3”
需要对http开始,?结束之间的字符串换成“abc”,在php的str_replace函数里,该如何写?谢谢 分享到:
------解决方案--------------------
str_replace 用不了正则,用preg_replace 吧
------解决方案--------------------
$urls = array("http:\/\/www.sina.com\/music1\/23412455.mp3?time=2234523&type=mp3",
"http:\/\/www.sina.com\/music2\/4325243.mp3?time=2234523&type=mp3",
"http:\/\/www.sina.com\/music3\/346553.mp3?time=2234523&type=mp3");
foreach($urls as $url){
echo preg_replace('@http(.*?)\?@i','abc',$url).'
';
}

www.phpzy.comtrue/phprm/13037.htmlTechArticlephp的str_replace()函数使用正则解决方法 php的str_replace() 函数使用正则 字符串如下: “http:\/\/www.sina.com\/music1\/23412455.mp3?time=2234523type=mp3” “http:\/\/www.sina.com\/music3\/346553.mp3?time=2234523nbsp...

相关文章

相关频道:

PHP之友评论

今天推荐