1

Is it correct and valid to use something like this:

<noscript>
<?php require_once 'somefile.php'; ?>
</noscript>

I've been searching for this answer a lot but unfortunately not much luck. Here is a quote from one of the answers by @SLaks on this page.

"If you put PHP code inside a tag, it will always execute, whether Javascript is enabled or not. However, the code's output will only be visible if Javascript is disabled."

However I am not very clear if it is valid to use php within a <noscript> tag.

4

4 回答 4

2

当然是。<noscript>在 PHP 预处理之后评估客户端。因此,无论您放入什么somefile.php,都会对其进行处理,然后将结果发送到<noscript>标签内的客户端。但是,正如 Slaks 所说,在禁用 JS 之前不会显示生成的输出。

只要生成的页面是有效的 HTML,您在页面中包含 PHP 的方式与 HTML 验证无关。

于 2013-07-19T07:32:32.397 回答
2

PHP 对文本流进行操作。它不关心文本是什么。它要么只是输出输入,要么(在一个<?php部分内)运行 PHP。它不知道 HTML。

有效性(在此上下文中)仅在生成的 HTML 的上下文中很重要。如果 PHP 输出有效内容,则 HTML 将有效,这取决于require_once 'somefile.php';输出的内容。

于 2013-07-19T07:36:18.693 回答
1

哦,当然可以。Noscript 旨在在用户禁用 JavaScript 时使用,为什么不呢?但请注意,它总是在渲染页面时执行。互联网上几乎所有用户都使用 JS,因此可能会有点开销。

于 2013-07-19T07:32:10.203 回答
1

在标签中使用 PHP 是有效的 - PHP 在服务器上进行评估,而不是发送到客户端。

于 2013-07-19T07:32:54.567 回答