Home > Backend Development > PHP Tutorial > 获取“包含文件执行结果”的字符串

获取“包含文件执行结果”的字符串

WBOY
Release: 2016-06-23 14:12:22
Original
850 people have browsed it

为描述问题,下面给出一简单模型:
比如有一文件 a.php,内容如下:

<div id='top'>    <?php $user="张三"; ?>    <p>欢迎你:<?php print $user ?> <a href='../public/logout.php'>注销</a></p></div>
Copy after login


有另一文件 b.php
<?php$s=file_get_contents('a.php',1);?>
Copy after login


在 b.php 中虽然能读取文件 a.php 的内容,却不是执行后的内容,若希望能解释 php 中的代码,使 $s 得到如下的结果,有什么好的办法吗?
<div id='top'>    <p>欢迎你:张三 <a href='../public/logout.php'>注销</a></p></div>
Copy after login


回复讨论(解决方案)

直接require/include进来

直接require/include进来
这个我知道,但是想获得这个字符串~~~

$s=file_get_contents('http://localhost/a.php');

include之后 替换成自己想要的具体内容

b.php修改如下

ob_start();include 'a.php';$s = ob_get_clean);
Copy after login

上面少了个括号

ob_start();include 'a.php';$s = ob_get_clean();
Copy after login

问题换了一种思路解决了,还是谢谢楼上各位!!!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template