在PHP中寻找一些REGEX帮助

时间:2013-02-21 10:44:34

标签: php regex

我有一个字符串:

[COLOR=gray]A bunch of text.[/COLOR]

我想写一个preg_replace删除"[COLOR=gray]""[/COLOR]"之间的所有内容 - 如果有可能删除这些标记,那就太好了,否则我可以做一个之后简单的替换。

1 个答案:

答案 0 :(得分:2)

$str  = 'dfgdfg[COLOR=gray]A bunch of text.[/COLOR]dfgdfgdfgfg';

$str1 = preg_replace('/\[COLOR=gray\].*\[\/COLOR\]/',"",$str);

echo $str1;

OR

如果COLOR不总是灰色

$str  = 'dfgdfg[COLOR=gray]A bunch of text.[/COLOR]dfgdfgdfgfg';

$str1 = preg_replace('/\[COLOR=\w+\].*\[\/COLOR\]/',"",$str);

echo $str1;
相关问题