繁体   English   中英

获取php文件的内容

[英]Get content of the php file

如何从另一个php文件中的一个php文件获取所有当前代码?

就像,我们在文件a.php包含一些功能。

还有文件b.php ,我们想要从a.php获取所有代码(不运行任何功能),并在请求时将其回显到浏览器。

(在b.php内部):

$content = get_all_file_text(a.php);
echo $content;

谢谢。

似乎每个人都喜欢file_get_contents,这是我的建议,当您尝试将其输出到浏览器时:

file_get_contents + Highlight_string

http://php.net/manual/zh/function.highlight-string.php

这似乎很简单,但是不幸的是,浏览器会将<?php解释为HTML标记的开头。

为避免这种情况,必须在PHP代码上使用htmlentities。 另外,要保留格式,请使用nl2br函数。

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));

这将在浏览器中产生正确的输出。

我也喜欢Highlight_string函数的答案。

请参阅此方法:

http://de2.php.net/manual/en/function.file-get-contents.php

这会给您返回一个字符串,您可以轻松地向客户发送该字符串。

美好的一天。

查看此页面:

http://de2.php.net/manual/en/function.file-get-contents.php

这是一个例子:

<?php
$file = file_get_contents('b.php');
echo $file;
?>

我相信您正在寻找file_get_contents()函数。 查看www.php.net/file_get_contents

请检查此代码...

a.php

<?php
echo file_get_contents("http://localhost/yourpath/b.php");
?>

b.php

<?php
 echo "HELLO WORLD!!!";
?>

我认为您正在寻找的是: http : //php.net/manual/en/function.file-get-contents.php

readfile将比file_get_contents更简单

readfile读取文件并将其输出到一个函数中,而file_get_contents会将其读取为字符串,然后必须将其输出

php.net/readfile

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM