Reputation: 3864
I need to echo entire content of included file. I have tried the below:
echo "<?php include ('http://www.example.com/script.php'); ?>";
echo "include (\"http://www.example.com/script.php\");";
But neither works? Does PHP support this?
Upvotes: 18
Views: 77410
Reputation: 31
Matt is correct with readfile()
but it also may be helpful for someone to look into the PHP file handling functions
manual entry for fpassthru
<?php
$f = fopen($filepath, 'r');
fpassthru($f);
fclose($f);
?>
Upvotes: 0
Reputation: 5165
This may not be the exact answer to your question, but why don't you just close the echo statement, insert your include statement, and then add a new echo statement?
<?php
echo 'The brown cow';
include './script.php';
echo 'jumped over the fence.';
?>
Upvotes: 1
Reputation: 2902
Shortest way is:
readfile('http://www.mysite.com/script.php');
That will directly output the file.
Upvotes: 4
Reputation: 129
Not really sure what you're asking, but you can't really include something via http and expect to see code, since the server will parse the file.
If "script.php" is a local file, you could try something like:
$file = file_get_contents('script.php');
echo $file;
Upvotes: 1
Reputation: 180177
Just do:
include("http://www.mysite.com/script.php");
Or:
echo file_get_contents("http://www.mysite.com/script.php");
Notes:
allow_url_fopen
to be on for your PHP installation. Some hosts turn it off.Upvotes: 25
Reputation: 49396
Echo prints something to the output buffer - it's not parsed by PHP. If you want to include something, just do it
include ('http://www.mysite.com/script.php');
You don't need to print out PHP source code, when you're writing PHP source code.
Upvotes: 3