Remove text between tags using a regular expression
How to remove text between br tags , using regexp
<br />var j=; var g=; g+=G;j+=30006;g+=a;g+=u;g+=l;g+=t;<br />
"var" and ";" i开发者_如何学Pythons always exist, but other words and symbols may vary, something like this:
<br />var e=; var x=; x+=tos;x+=ах,;<br />
etc...
these lines appear in random order:
<br />Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br />var j=; var g=; g+=G;j+=30006;g+=a;g+=u;g+=l;g+=t;<br /> Donec condimentum neque quis magna consectetur ut aliquam quam dictum. Fusce sed elit purus, lobortis tincidunt libero.<br />Nunc ultrices augue non augue tristique in aliquet urna adipiscing.<br /><br />var ... ;<br />
thanks!
The regexp you want would be
<br\s\/?>.*?var.*?;.*?<br\s\/?>
and just replace the output by <br /><br />
.
If all you want is the output <br /><br />
, you don't need regular expressions:
$result = "<br /><br />";
It's just a constant!
if count of <br />
elements vary you can use substr_count()
to count <br />
elements and then output same amount separately.
If you have to do it for a whole text and by pairs of <br/>
you can do something like that :
$str = 'test0 <br />var j=; var g=; g+=G;j+=30006;g+=a;g+=u;g+=l;g+=t;<br /> test1 <br /> test2';
$result = preg_replace('`<br */>.*?<br */>`s','<br/><br/>',$str);
var_dump($result);
精彩评论