不解析的Php文件包括(Php file that does not parse includes)

编程入门 行业动态 更新时间:2024-10-17 09:39:58
不解析的Php文件包括(Php file that does not parse includes)

我的目标是在服务器上自动创建一个带有以下html / php的文件,但是它包含了php包含,所以当构建页面时,它还包括include中的所有内容。

我想要include("../includes/right.html"); 单独留在生成的页面中,但我想要解析其他php变量。

<?php // Start the buffering // ob_start(); ?> <?php echo $name; ?> test text line one <?php include("../includes/right.html"); ?> test text line two <?php // Putting content buffer into file // file_put_contents('mypage.html', ob_get_contents()); ?>

My goal is to have a file with the following html/php created on the server automatically which it does do, however it includes the php includes as well so when the page is build it includes everything that is in the include as well.

I would want include("../includes/right.html"); to be left alone in the page that is generated,but I want other php variables to be parsed.

<?php // Start the buffering // ob_start(); ?> <?php echo $name; ?> test text line one <?php include("../includes/right.html"); ?> test text line two <?php // Putting content buffer into file // file_put_contents('mypage.html', ob_get_contents()); ?>

最满意答案

这可以直接来自http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc上的PHP手册。这称为nowdoc语法,随PHP 5.3一起提供。 对于像这样的事情,这通常是最好的做法。

echo <<<'EOT' My name is "$name". I am printing some $foo->foo. Now, I am printing some {$foo->bar[1]}. This should not print a capital 'A': \x41 EOT;

'EOT'和EOT之间的任何东西; 将在页面上呈现为文本而不进行任何解析。

This is straight from the PHP manual at http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc This is called nowdoc syntax and comes with PHP 5.3. It's generally the best practice for something like this.

echo <<<'EOT' My name is "$name". I am printing some $foo->foo. Now, I am printing some {$foo->bar[1]}. This should not print a capital 'A': \x41 EOT;

anything between 'EOT' and EOT; will be rendered on the page as text with no parsing done whatsoever.

更多推荐

php,html,includes,电脑培训,计算机培训,IT培训"/> <meta name="description

本文发布于:2023-08-05 03:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1428128.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   Php   file   includes   parse

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!