Get content of the php file
How to get all the current code from one php-file inside other php-file?
Like, we have file a.php
with some functions inside.
And file b.php
, where we w开发者_如何学编程ant to get all the code (without running any functions) from a.php
and echo it to the browser when requested.
Like
(inside b.php
):
$content = get_all_file_text(a.php);
echo $content;
Thanks.
seems everyone so like file_get_contents, here is my suggestion as you try to output it to browser :
file_get_contents + highlight_string
http://php.net/manual/en/function.highlight-string.php
This seems simple enough, but unfortunately the browser will interpret <?php
as the beginning of an HTML tag.
To avoid this, you must use htmlentities on the PHP code. Also, to preserve formatting, the nl2br function.
c.php:
<?php
$f='snizz';
function plip($f){ echo $f; }
$r=array(1,2,3,32);
a.php:
<?php
$f=file_get_contents('c.php');
echo nl2br(htmlentities($f));
This will produce the correct output in the browser.
I like the answer with the highlight_string function, too.
See this method:
http://de2.php.net/manual/en/function.file-get-contents.php
This gives you back a string that you can easily dish out to your clients.
Good day.
Check out this page:
http://de2.php.net/manual/en/function.file-get-contents.php
Here is an example:
<?php
$file = file_get_contents('b.php');
echo $file;
?>
I believe you're looking for the file_get_contents() function. Check out www.php.net/file_get_contents
I think you're looking for this: http://php.net/manual/en/function.file-get-contents.php
readfile
will be simpler than file_get_contents
readfile
reads the file and outputs it in one function, whereas file_get_contents
reads it into a string which must then be outputted
php.net/readfile
Please check this code...
a.php
<?php
echo file_get_contents("http://localhost/yourpath/b.php");
?>
b.php
<?php
echo "HELLO WORLD!!!";
?>
精彩评论