MrGreggles
MrGreggles

Reputation: 6175

What's the easiest way to retrieve the contents of a webpage via PHP?

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

Answers (3)

Kyle Cronin
Kyle Cronin

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

Michael Todd
Michael Todd

Reputation: 17051

$pageContent = file_get_contents($url);

From: file_get_contents

Upvotes: 6

Caleb Groom
Caleb Groom

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

Related Questions