PHP利用正则表达式替换标签_PHP教程

WBOY
Release: 2016-07-12 09:04:57
Original
700 people have browsed it

PHP利用正则表达式替换标签

$str = '你好吗,还可以吧一般般了[link url="http://www.chinanews.com/sh/2015/11-13/7621991.shtml"]义昌大桥爆炸垮塌致14死案宣判 被告人张根林死缓[/link]一点都不好怎么办啊areyouok[][link url="http://www。baidu。com"]这个正则表达式确定好使嘛[/link]are幽邃';
 
$string = '你好这是一个连接preg_match_all你好吗这还是几日人了'; 
 
 
preg_match_all('/(.*?)/i',$string,$arr);
preg_match_all('/\[link url=\"(.*?)\".*?\](.*?)\[\/link\]/i',$str,$arr);
var_dump($arr);
 
if($arr){
    foreach($arr[0] as $ke=>$va){
        $str=str_replace($va,''.$arr[2][$ke].'',$str);
    }
}
echo $str;

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1071280.htmlTechArticlePHP利用正则表达式替换标签 $str = 你好吗,还可以吧一般般了[link url=http://www.chinanews.com/sh/2015/11-13/7621991.shtml]义昌大桥爆炸垮塌致14死案宣判...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!