Include whole content of a file and echo it

Elliott picture Elliott · May 28, 2009 · Viewed 65.1k times · Source

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?

Answer

ceejayoz picture ceejayoz · May 28, 2009

Just do:

include("http://www.mysite.com/script.php");

Or:

echo file_get_contents("http://www.mysite.com/script.php");

Notes:

  • This may slow down your page due to network latency or if the other server is slow.
  • This requires allow_url_fopen to be on for your PHP installation. Some hosts turn it off.
  • This will not give you the PHP code, it'll give you the HTML/text output.