Home > php教程 > php手册 > PHP利用正则表达式替换标签

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 08:51:04
Original
1160 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;

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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template