fivestringsurf Posted September 29, 2013 Share Posted September 29, 2013 I built a custom templating class that uses DOMDocument to manipulate some of the nodes/tags within my html. I run into all kinds of problems when I use inline js (js that lives on page) Most notably with < and & used in the js itself. This code exibits some of the problems: $domStr = ' <!DOCTYPE html> <head> <meta charset="utf-8"/> <title>my page</title> <script> var elem = "<div>some content</div>"; </script> </head> <body> <div> MY PAGE </div> </body> </html> '; $doc = new DOMDocument(); libxml_use_internal_errors(true);//prevents tags in js from throwing errors; see php.net manual $doc->formatOutput = true; $doc->strictErrorChecking = false; $doc->preserveWhiteSpace = true; $doc->loadHTML($domStr); echo $doc->saveHTML(); exit; and the html output is: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>my page</title> <script> var elem = "<div>some content"; </script> </head> <body> <div> MY PAGE </div> </body> </html> You'll notice that the closing </div> tag is removed. ??? I have very dissapointed with domdocument overall as it doesn't seem to always do what it promises to do...even with preserving space/formatting etc. I'm to the point at which I might just abandon domdocument altogether and parst the html myself with regex (yuck) any expert advice in this matter would be greatly appretiated. Quote Link to comment https://forums.phpfreaks.com/topic/282535-domdocument-wrecking-inline-javascript/ Share on other sites More sharing options...
fivestringsurf Posted October 3, 2013 Author Share Posted October 3, 2013 BUMP Quote Link to comment https://forums.phpfreaks.com/topic/282535-domdocument-wrecking-inline-javascript/#findComment-1452429 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.