note 126479 deleted from domdocument.loadhtml by cmb

From: Date: Wed, 06 Oct 2021 07:56:59 +0000
Subject: note 126479 deleted from domdocument.loadhtml by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-217038@lists.php.net to get a copy of this message
Note Submitter: ar_m dot dot dot at yahoo dot de ---- If you use a template with Javascript and php embedded and again embedd this via loadHTMLFile, you may experience difficulties. In the following example template.php is interpreted just fine on its own, but when embedded in the index.php it throws the syntaxError unexpected token '<' and the ReferenceError that par is not defined in the onload statement. template.php: _______________ <!DOCTYPE html> <html> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <script type="text/javascript"> var testvar=<?php echo "'blub'"; ?> var par =document.createElement("p"); var text=document.createTextNode(testvar); par.append(text); </script> </head> <body onload="document.body.append(par);"> can you see a blub after this text: <noscript> probably not</noscript> </body> </html> _______________ index.php: _______________ $dom=new DOMDocument('1.0','utf-8'); libxml_use_internal_errors(true); $dom->loadHTMLFile("template.php"); echo $dom->saveHTML(); flush(); ob_flush(); _______________ I want this to be a part of this Docu since there are numerous threads on where this syntax error comes from, including that you may have used a .html instead of a .php-file and different types of parenthesis. I have not seen anybody comment on this and you actually want to know this in the beginning to structure the project.

« previous php.notes (#217038) next »