删除两个类似BBcode的标签内的所有内容

时间:2014-03-26 17:50:49

标签: php

我将以下字符串存储在变量中(取自数据库)

$string = 'some simple text i need [link href="http://www.somelink.com/..."]some link i dont need here[/link] some simple text i need too.';

我试图从字符串中删除以下部分:

[link href="http://www.somelink.com/..."]some link i dont need here[/link]

这是我希望的最终输出:

some simple text i need some simple text i need too.

如何使用PHP实现此目的?

1 个答案:

答案 0 :(得分:3)

使用此正则表达式~\[link(.*?)\[\/link]~

<?php
$string = 'some simple text i need [link href="http://www.somelink.com/..."]some link i dont need here[/link] some simple text i need too.';
echo $str = preg_replace("~\[link(.*?)\[\/link]~","", $string);

<强> OUTPUT :

some simple text i need some simple text i need too.

enter image description here