I have some text for ex: This is <b>an</b> example <b>text</b>.
How would I remove all the text that is within bold tags, so it should output this:
This is example.
Use preg_replace()
If you would like to remove a simple tag along with the text inside it:
<?php
$string = 'This is <b>an</b> example <b>text</b>';
echo preg_replace('/(<b>.+?)+(<\/b>)/i', '', $string);
Output:
This is example
And whit a regular expression (class, id), spacing errors and antislashe:
<?php
$string = 'This is <b class="c1" id=\'c2\'>an</b> example <b>text</B >';
echo preg_replace('@<(\w+)\b.*?>.*?</\1.*?>@si', '', $string);
Output:
This is example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With