user2800761
user2800761

Reputation: 2335

Read a php file that returned html

I tried to use:

file_get_contents("www.example.com/example.php");

but it did not work, I think it's because it is a php file. It works if it is "example.html". I do not want the php code, it is the back-end and i understand that's impossible. All i want from "example.php" is the html within it. Because the layout is:

<?php
//php
?>
<html>
</html>

So although it is a php file, is there a way of returning it's front-end code into a string?

Thanks.

Upvotes: 0

Views: 85

Answers (2)

markus
markus

Reputation: 40675

If you pass a web URL to file_get_contents() you're making basically a normal http request to that URL, which means it's impossible to get any PHP back since the web server sends only HTML to the client and you're asking the client for the content of the page.

So if you do (source: PHP manual):

$homepage = file_get_contents('http://www.example.com/');
echo $homepage;

You will echo the HTML of that URL which you stored (as a string) in $homepage.

Your mistake is that you forgot to include the protocol (http or https).

Upvotes: 3

Barmar
Barmar

Reputation: 781004

You need to specify the protocol:

file_get_contents("http://www.example.com/example.php");

Otherwise, it thinks it's just a filename on the server.

Upvotes: 3

Related Questions