Remove text that is in the middle of <b></b>
I Have Text in the middle of <b></b>
Eg:
La <b>la</b>: the 1 <br></br>Aventuroj <b>a开发者_StackOverflowventuro</b>: adventure 2 <br></br>de <b>de</b>: by, from, of, since 3 <br></br>Mirlando <b>miri</b>: marvel, marvel at, wonder<br/><b>lando</b>: country, land 4 <br></br>by <b>ba</b>: bah, nuts, pooh 5 <br></br>for <b>for</b>: away 6 <br></br>
I would like maybe a regex that would strip the text and the <b></b>
from the string
Thanks
★✩
The simplest way is to use preg_replace()
:
$output = preg_replace('!<b>.*?</b>!s', '', $input);
The s
on the end is a flag. See Pattern Modifiers for a list of flags.
s (PCRE_DOTALL)
If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier.
Generally speaking however regexes are a poor tool for querying and manipulating HTML or XML. PHP has a number of inbuilt HTML parsers and for a robust solution you should use those instead, as a general rule.
preg_replace("/<b>(.*?)<\/b>/ism","",$str);
精彩评论