I want to write a function to retrieve the contents of a webpage so it works like:
$url = "example.com";
$pageContent = RetrievePageContent($url);
What would be the easiest way to do this?
Thanks in advance for your help!
I want to write a function to retrieve the contents of a webpage so it works like:
$url = "example.com";
$pageContent = RetrievePageContent($url);
What would be the easiest way to do this?
Thanks in advance for your help!
The easiest way is file_get_contents, which does exactly what you want:
$url = "http://example.com";
$pageContent = file_get_contents($url);
You can use the fopen command and pass it a URL. However, this ability might be disabled by your host. The best practice would be to use the cURL functions. The documentation includes sample code that does exactly what you're trying to do.