The following is automatically output via editor:
<a href="https://someurl.com/1001-web-file.pdf">1001-web-file</a>
I would like to add an ID:
<a id="replace" href="https://someurl.com/1001-web-file.pdf">1001-web-file</a>
Then use str_replace
and a regular expression to find the anchors in question and replace with:
<a href="https://someurl.com/1001-web-file.pdf"><img src="https://someurl.com/1001-web-file-pdf-290x300.jpg"/></a>
What I've managed to do is:
$replace = array(
'<a id="pdfthumb" href="' => '<img src="',
'.pdf">pdfthumb</a>' => '-pdf-290x300.jpg"/></br>'
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
This works to tear down the anchor tag and rebuild as an img. But I can't do much more. I played around with some regex to create a wildcard and realized I need to create a variable for the href to use when I rebuild the HTML, but I'm stuck.
Any insight is much appreciated :)