Home > Backend Development > PHP Tutorial > PHP uses regular expressions to replace tags_PHP tutorial

PHP uses regular expressions to replace tags_PHP tutorial

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

PHP uses regular expressions to replace tags

$str = 'How are you? It's okay. It's just so-so. [link url="http://www.chinanews.com/sh/2015/11-13/7621991.shtml"] Yichang Bridge exploded and collapsed, killing 14 The case was sentenced to a suspended death sentence for the defendant Zhang Genlin[/link] It’s not good at all. What should I do? areyouok[][link url="http://www.baidu.com"]Is this regular expression sure to work[/link]areyousui ';
$string = 'Hello, this is a connectionHow are you? How many days have we been here';
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 uses regular expressions to replace tags $str = How are you? It’s ok. Just so-so [link url= http://www.chinanews.com/sh/2015/11-13/7621991.shtml] The verdict was announced in the case of Yichang Bridge explosion and collapse that killed 14 people...
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