php - why does noscript move into body tag instead of head tag


On my PHP project, I put noscript tag in head tag like below..

<!DOCTYPE html>

This is a template file which a php script gets and renders.

the PHP script is like below..

$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 );

echo $dom->saveHtml();

in localhost, it displays as it is. so it is ok.

But when i push this code to my server and i see this page on browser, noscript tag moves into body tag like below..


Do you guess why it causes ??
detail about our server environment is below. There are some differences although i don't think it causes the problem...

- XAMPP on my Mac
- Apache/2.4.18 (Unix) PHP/5.6.20

- Apache/2.2.15 (Unix) PHP/5.6.15

and i also tested like below code.

echo <<< EOM
<!DOCTYPE html>

it works on both environment. so DOMDocument may be the culprit.. ? i don't know... but i cannot use this code.. because of our framework. so i still have to search the problem..

and these are apache modules on our server.

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)



i found the answer by myself. in my server, libxml version is 2.7.6.
in my localhost, libxml version is 2.8.0.
according to this changelog,
until 2.8.0, there was the bug ofHTML parser error with <noscript> in the <head>
and this bug was fixed in release of version 2.8.0.
so i upgrade libxml on my server to 2.8.0, which fixed the problem!

People are also looking for solutions to the problem: php - How to set a boolean to true if the button is clicked?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.