将include的值传递给变量 [英] Pass value of a include to a variable

查看:132
本文介绍了将include的值传递给变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将包含的结果传递给变量?

Is it possible to pass the result of an include to a variable?

让我们考虑这个简单的文件'example.html':

Let's consider this simple file 'example.html':

<p>some HTML</p>

在PHP文件中,我们如何将此文件的内容传递给变量?
我试过:

In a PHP file, how can we pass the content of this file to a variable? I tried:

$my_variable = include('example.html');

它包含文件,但 $ my_variable 1

推荐答案

如果你只想得到您可以使用此文件的内容:

If you just want to get the content of file you can use this :

$data = file_get_contents("example.html");
echo htmlentities($data);

或者这个:

ob_start();
readfile("example.html");
$data = ob_get_clean();
echo htmlentities($data);

这篇关于将include的值传递给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆