我将以下字符串存储在变量中(取自数据库)
$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实现此目的?
答案 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.