【发布时间】:2016-08-18 08:16:24
【问题描述】:
在我的 PHP 项目中, 我把 noscript 标记放在 head 标记中,如下所示..
<!DOCTYPE html>
<head>
<noscript></noscript>
</head>
<body>
</body>
</html>
这是一个 模板 文件,由 php 脚本获取并呈现。
PHP 脚本如下..
$file = file_get_contents( $templatePath );
$dom = new \DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true; // not working
$dom->encoding = 'UTF-8';
libxml_use_internal_errors( true );
$dom->loadHTML( mb_convert_encoding($file, 'HTML-ENTITIES', 'UTF-8') , LIBXML_NOERROR | LIBXML_NOWARNING );
libxml_clear_errors();
echo $dom->saveHtml();
在本地主机中,它按原样显示。所以没关系。
但是当我将此代码推送到我的 服务器 并且我在浏览器上看到此页面时, noscript 标签移动到 body 标签中,如下所示..
<html>
<head></head>
<body>
<noscript></noscript>
</body>
</html>
你猜为什么会导致 ??
关于我们的服务器环境的详细信息如下。
有一些差异,虽然我不认为它会导致问题......
【环境】
本地
- 我的 Mac 上的 XAMPP
- Apache/2.4.18 (Unix) PHP/5.6.20
服务器
- Apache/2.2.15 (Unix) PHP/5.6.15
=========================================
我也像下面的代码一样进行了测试。
echo <<< EOM
<!DOCTYPE html>
<head>
<noscript></noscript>
</head>
<body>
</body>
</html>
EOM;
它适用于两种环境。 所以 DOMDocument 可能是罪魁祸首..?我不知道... 但我不能使用这个代码..因为我们的框架。 所以我仍然需要搜索问题..
=============================================== 这些是我们服务器上的 apache 模块。
Loaded Modules:
core_module (static)
mpm_prefork_module (static)
http_module (static)
so_module (static)
auth_basic_module (shared)
auth_digest_module (shared)
authn_file_module (shared)
authn_alias_module (shared)
authn_anon_module (shared)
authn_dbm_module (shared)
authn_default_module (shared)
authz_host_module (shared)
authz_user_module (shared)
authz_owner_module (shared)
authz_groupfile_module (shared)
authz_dbm_module (shared)
authz_default_module (shared)
ldap_module (shared)
authnz_ldap_module (shared)
include_module (shared)
log_config_module (shared)
logio_module (shared)
env_module (shared)
ext_filter_module (shared)
mime_magic_module (shared)
expires_module (shared)
deflate_module (shared)
headers_module (shared)
usertrack_module (shared)
setenvif_module (shared)
mime_module (shared)
dav_module (shared)
status_module (shared)
autoindex_module (shared)
info_module (shared)
dav_fs_module (shared)
vhost_alias_module (shared)
negotiation_module (shared)
dir_module (shared)
actions_module (shared)
speling_module (shared)
userdir_module (shared)
alias_module (shared)
substitute_module (shared)
rewrite_module (shared)
proxy_module (shared)
proxy_balancer_module (shared)
proxy_ftp_module (shared)
proxy_http_module (shared)
proxy_ajp_module (shared)
proxy_connect_module (shared)
cache_module (shared)
suexec_module (shared)
disk_cache_module (shared)
cgi_module (shared)
version_module (shared)
php5_module (shared)
ssl_module (shared)
【问题讨论】:
-
<noscript>标签是 invalid direct descendents of<html>tags,所以它被放置在<body>标签内。如果您希望它位于<head>标记内,请更正您的 HTML 文档。 -
> 系统发育 哎呀……对不起。我弄错了上面的代码.. noscript 标签在 head.
-
具体来说,我正在努力将 AMP 应用到我们的网站。 AMP 代码头部没有脚本。喜欢这个示例代码..ampproject.org/docs/get_started/create/basic_markup.html
-
This looks good to me。我猜问题出在其他地方?
-
您没有做过类似忘记更新服务器上的实际模板文件的事情吧?因为我无法重现您的问题(即使 PHP 5.2 将
<noscript>元素保留在<head>元素内)。