How can I use PHP to include an external webpage? (sort of like the wordpress theme preview.)
I want (X)HTML STRICT compliant code – no iFrame and preferably no javascript.
The idea is that I am making a sandbox for clients to view webpages in my controlled environment. The other thing is that the webpages being included should not be visible without the “sandbox” wrapper”.
EDIT:
According to some commentators, GoDaddy has cUrl. The next part of the question becomes – how do I strip out the headers and footers of the html in php so that just the contents of the body tag remain? I would rather use php string functions than regex.
Try Using Curl:
Just call that function as-is with your url and it should echo out the whole webpage into the php page.
However, you may need to rewrite links to assets, such as stylesheets and images using some regex. (Replace “/image.jpg” with “http://mydomain.com/image.jpg“).
Curl usually is installed on shared hosts.
If you want to just get the page’s body, or head, you can use simplexml or regex expressions for that. (If the html is well-formed, simplexml is great for traversing the DOM).