Forum Moderators: coopster
I need to check all the text in an HTML content but ignore the tags attributes.
For example:
$content = '<a class="text">text</a> This is some text and other elements <b class="text">Goes here</b>';
$check = 'text';
I've gone this far:
$content = preg_replace('~(<[^>]+>)?' . preg_quote($check, '~') . '(</[^>]+>)?~', '$1<b>'.$check.'</b>$2', $content);
but it still fails. It succeeds ignoring the a tag attributes but it does the bold to the b tag:
<a class="text"><b>text</b></a> This is some <b>text</b> and other elements <b class="<b>text</b>">Goes here</b>
By ignoring I mean ignoring the data between < and >. Not ignoring the whole tag. (Otherwise I would use strip_tags())