I have a string:
[COLOR=gray]A bunch of text.[/COLOR]
And I would like to write a preg_replace
that removes everything between "[COLOR=gray]"
and "[/COLOR]"
-- if it's possible to remove those tags as well, that's great, otherwise I can do a simple replace afterward.
$str = 'dfgdfg[COLOR=gray]A bunch of text.[/COLOR]dfgdfgdfgfg';
$str1 = preg_replace('/\[COLOR=gray\].*\[\/COLOR\]/',"",$str);
echo $str1;
OR
if COLOR is not always gray
$str = 'dfgdfg[COLOR=gray]A bunch of text.[/COLOR]dfgdfgdfgfg';
$str1 = preg_replace('/\[COLOR=\w+\].*\[\/COLOR\]/',"",$str);
echo $str1;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.