Reputation: 6175
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!
Upvotes: 0
Views: 286
Reputation: 79103
The easiest way is file_get_contents, which does exactly what you want:
$url = "http://example.com";
$pageContent = file_get_contents($url);
Upvotes: 4
Reputation: 17051
$pageContent = file_get_contents($url);
From: file_get_contents
Upvotes: 6
Reputation: 155
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.
Upvotes: 1