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 `href`s and `img`s 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 `href`s and `img`s 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 `href`s. How can we expand this to also consider `img`s?

* [Change a relative URL to absolute URL](https://stackoverflow.com/questions/3342785/change-a-relative-url-to-absolute-url)

Would a regex be in order? Or since we're dealing with a lot of output should we use DOMDocument?