I am working on including a site with php using file_get_contents()
I have xampp set up so I run everything locally.
The page that I have included is located at sub.domain.dev
while I am running the script from the main domain (domain.dev).
Of course doing this will cause all images in the included html page not to load since the img source is not a full url but "img/bg.gif".
As a regex newbie I have managed to replace the img src url of the html page with the full path so they load with this *embarrassing* code....
$site_content = file_get_contents('http://sub.domain.dev/');
$match = '/src="images/';
$url = 'http://sub.domain.dev/';
$replace = 'src="'.$url.'img';
$site_content = preg_replace($match,$replace,$site_content);
Though not fancy, it does work...
However, the css won't load due to the wrong path and even if I replaced it will the full path the image url's in the css would be pointing to the wrong source.
So I was thinking if I could get the css file content the same way as I did with the html file_get_contents()
, run a preg_replace on all url's and paste it directy into the $site_content it would work.
So I see it like this...
Get css file contets with file_get_contents()
Locate the css tag in the html content variable and remove it from the string (preg_replace?)
Replace all url's in the content with the full http://sub.domain.dev/ with preg_replace
insert the css content into the head of the html content variable.
Would anyone be willing to help me with the regex patterns for this? I find them to be difficult...
Overall help and pointer also greatly appreciated, perhaps theres a better way of doing this