I have a PHP file. I want to read the PHP code written inside that file. The script I am executing is in the file 'test.php'.
<?php
$test = file_get_contents('test.php');
echo '<pre>'.$test.'</pre>';
?>
The output in browser window is:
'.$test.'
'; ?>
another test on the file:
<!DOCTYPE html>
<html>
<head>
<title>Canvas Home</title>
<link rel="shortcut icon" href="http://localhost/collaborate/icons/collaborate.ico">
<?php
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheets/".basename(__FILE__,'.php').".css\">";
echo "<script type=\"text/javascript\" src=\"js/".basename(__FILE__,'.php').".js\"></script>";
?>
<link rel="stylesheet" type="text/css" href="stylesheets/navs.css">
</head>
<body>
<div></div>
</body>
</html>
gave the output:
"; echo ""; ?>
Can someone explain me what is happening in the first file? I expected the returned string to be simply echoed.
Also in the second file, the first simple HTML part is echoed and hence gets interpreted as HTML, understood. But what happens then? Why is the echo command itself displayed?
I basically want to achieve reading the source of any script file rather than it being executed, i want it displayed in the browser window.