Code in index.php
code in hello.php
This is happening because readfile echos to the screen for you. echo readfile()
is unnecessary. After echoing, readfile
returns the number of bytes that it read, so that's where the 47
is coming from.
You can just do:
readfile('hello.php');
or you can use
echo file_get_contents('hello.php');
if you choose.
Also, I suggest you check the source of your page in your browser (consult your browser's docs). Chances are, you'll see the PHP file clearly there. Your browser is probably trying to render the response as an HTML file. It's trying to parse <?php
as an HTML tag. That's why it's not displayed.
To get around this, you can try to add
header('Content-type: text/plain');
before you echo your hello.php file to the screen. This should tell the browser that it's receiving just a text file and not to try to parse it as HTML.
The behavior for php file is same as other files. If you go to page source you will see the <?php
tag is also present.