There are a lot of posts on converting relative to absolute paths in PHP. I’m looking for a specific implementation beyond these posts (hopefully). Could anyone please help me with this specific implementation?
I have a PHP variable containing diverse HTML, including hrefs and imgs containing relative urls. Mostly (for example) /en/discover or /img/icons/facebook.png
I want to process this PHP variable in such a way that the values of my hrefs and imgs will be converted to http://mydomain.com/en/discover and http://mydomain.com/img/icons/facebook.png
I believe the question below covers the solution for hrefs. How can we expand this to also consider imgs?
Would a regex be in order? Or since we’re dealing with a lot of output should we use DOMDocument?
After some further research I’ve stumbled upon this article from Gerd Riesselmann on how to solve the absence of a
base hrefsolution for RSS-feeds. His snippet actually solves my question!http://www.gerd-riesselmann.net/archives/2005/11/rss-doesnt-know-a-base-url
Thank you Gerd! And thank you shadyyx to point me in the direction of
base href!