I need some help writing a regular expression pattern in PHP. I need to take a string containing HTML, find all anchor tags that contain a LOCAL href and remove the tags, while keeping the text within the tag.
Example:
<a href="/link1.html">Link 1</a>
<a href="../link2.html">Link 2</a>
<a href="http://www.localdomain.com/link3.html">Link 3</a>
should become:
Link 1
Link 2
Link 3
EDIT:
I’m looking for something like this:
function remove_internal_links($content) {
$pattern = '/<a href="([^"])/';
$content = preg_replace($pattern, '\\1', $content);
}
Where I need help (obviously) is with the $pattern.
Thanks!
You could use some third part library to parse the html like PHP Simple HTML DOM Parser