【问题标题】:incorrect php code output with embedded html带有嵌入 html 的错误 php 代码输出
【发布时间】:2017-02-20 14:06:54
【问题描述】:

我正在尝试在我的 php 代码中实现 html 代码。我用

<?php
echo <<< _END
//HTML HERE
_END;
?>

问题是_END;?&gt; 也显示在页面上。

我使用此代码在/etc/httpd/conf.d/mywebsite.conf 中编辑了我的网站文件夹的指令,并使用 mydomain.com/test 访问了 php 文件。未添加 .php 扩展名。如果我访问 mydomain.com/test.php 而不是 _END;?> 在我的 html 输出中,这是正确的。

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
#RewriteRule ^([a-z]+)\/?$ $1.php [NC]


RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html
#RewriteRule ^([a-z]+)\/?$ $1.html [NC]

</IfModule>

知道为什么我会在我的网站上看到_END;?&gt; 吗?

似乎隐藏 .html 可以正常工作,但 .php 被错误解释。

【问题讨论】:

    标签: php html apache


    【解决方案1】:

    _END 之前或之后有一个额外的空格。这是一个链接,将更详细地解释它。 heredoc

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-28
      • 1970-01-01
      • 2014-12-16
      • 2017-03-27
      • 2015-10-04
      • 2020-02-20
      • 1970-01-01
      • 2017-04-13
      相关资源
      最近更新 更多