使用PHP将相对URL转换为绝对URL以获得完整的网页

I am using PHP to read a HTML file:

$w = file_get_contents('http://localhost/site1/theme/default/about.html');

The PHP code is run from http://localhost/site1/. I have used simplexml to find things like images so src="images/image1.png" and change it to http://localhost/site1/theme/default/about/images/image1.png. This works but how would I change things like

background-image: url("../images/World1.png");

and

href="../../stylesheet.css" 

to absolute paths? I looked at url_to_absolute.php but couldn't get it to do what I need.