Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file_get_contents returns PHP code

When I use file_get_contents() function on a local file, the result contains php code, though I need HTML only.

Content of the file being read:

<?php echo '<p>Hello</p>';?>

And the result of file_get_contents called from a different file located in the same folder:

<?php echo file_get_contents('test.php'); //returns the following: string(31) "Hello'; ?>"

If I read a file from an external server, it returns HTML - as I would expect. So the question is: how do I get HTML output from the local file? Thank you all.

like image 243
user3382380 Avatar asked Jul 23 '14 11:07

user3382380


1 Answers

You can use the files url (not filepath), so it is processed by the server eg:

echo file_get_contents('http://website.com/test.php');

However include/require would be better, eg:

include 'test.php';
like image 111
Steve Avatar answered Sep 30 '22 18:09

Steve