我的需求是读取一个php文件的内容,并在前端显示内容。 为此,我使用了
$section = file_get_contents('test.php');
var_dump($section);
?>
但它正在打印值,并且在一些字符之后,它只是打印......而不是完整的内容。我尝试通过 echo 和 print_r 方法进行打印,但无论如何我都没有得到完整的内容。
我的 app.php 是这样的:
<?php
$data = array(
array('id' => 1, 'first' => "abc", 'last' => 'def', 'email' => 'abc@def.com'),
array('id' => 2, 'first' => "ghi", 'last' => 'jkl', 'email' => 'abc@def.com'),
array('id' => 3, 'first' => "mno", 'last' => 'pqr', 'email' => 'abc@def.com'),
array('id' => 4, 'first' => "stu", 'last' => 'vwx', 'email' => 'abc@def.com'),
array('id' => 5, 'first' => "Y", 'last' => 'Z', 'email' => 'abc@def.com'),
);
echo json_encode(array(
'success' => true,
'message' => 'loading data',
'data' => $data
));
?>
最佳答案
您需要escape像 <
这样的字符和 >
至 <
和 >
.
var_dump(htmlentities($section));
或者:
echo htmlentities($section);
如果您在浏览器中执行“查看源代码”,您会看到其余部分确实存在,但您的浏览器正在尝试将文本解释为 HTML。
另请注意 file_get_contents
没有 execute
PHP(在您的示例中为 test.php);它只是像读取文本文件一样读取文件。您可能想看看 include , include_once , require或 require_once如果您希望文件中的代码真正被执行。
关于php - php 中的 Var_dump 不打印仅显示的全部内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15635359/