Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8685263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:31:25+00:00 2026-06-12T22:31:25+00:00

This is a wierd problem, and I can’t see an easy solution. If you

  • 0

This is a wierd problem, and I can’t see an easy solution.

If you attempt to use DOM to parse a document that has a </head> tag contained within a javascript function, it doesn’t work correctly. It takes the </head> inside the javascript function as the closing </head> tag.

I have been wrestling with this for hours – any ideas?

<?php
$contents =
<<<EOF
<!DOCTYPE html>
<html><head>
<script>function myFunc() { var myVar = "<head></head>"; } </script>
</head>
<body><p>This is a test</p></body>
</html>
EOF;

//GET CONTENT & LOAD INTO DOM
$doc = new DOMDocument('1.0', 'UTF-8');
$doc->loadHTML($contents);

//STRIP OUT THE JAVASCRIPT
$scripts = $doc->getElementsByTagName('script');
$length = $scripts->length;
for ($i = 0; $i < $length; $i++) {
    $scripts->item(0)->parentNode->removeChild($scripts->item(0));
}

echo htmlentities($doc->saveHTML());
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:31:27+00:00Added an answer on June 12, 2026 at 10:31 pm

    Common Javascript issue: Use this instead:

    var myVar = "<head><\/head>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wierd problem that I can't seem to find the solution, probably
I have a very weird problem that I can't understand. This is C code:
Okey so I got a really wierd problem that I can't understand. i got
I have been experiencing a weird problem that I can't find a solution to.
I'm using django with app-engine-patch and I'm having this wierd problem running manage.py dumpdata
This is a weird problem. I have a solution for it, but I don't
This is a very weird problem. My app that runs just fine but somehow
this is a long question and weird problem that I hope to solve. My
In my application , i had wierd problem that when app goes background (press
I just came across this weird problem that is happening in IE. In the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.