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 8950241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:24:39+00:00 2026-06-15T13:24:39+00:00

I am using DOMDocument to load some user contributed HTML blocks and then manipulate

  • 0

I am using DOMDocument to load some user contributed HTML blocks and then manipulate them. It appears (assuming I am doing everything correctly) that DOMDocument is running the urls inside an href attribute through htmlentities. This is making my anchor tags which have ampersands in the query string come out incorrect.

Example:

$html = <<<HTML
<a href="http://foo.com?bar=baz&foo=bar">Foo</a>
HTML;

$dom = new DOMDocument;
$dom->loadHTML($html);

echo $dom->saveHTML();

The output becomes(notice the & in the url was converted to &amp;):

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><a href="http://foo.com?bar=baz&amp;foo=bar">Foo</a></body></html>

Additionally, during the call to $dom->loadHTML($html); the following warnings were output…

Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ‘;’ in
Entity, line: 1

I have no idea what that means.

Am I missing something?

  • 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-15T13:24:40+00:00Added an answer on June 15, 2026 at 1:24 pm

    The ampersand symbol is used in valid/compliant XHTML to determine HTML entity characters.

    See this reference list:
    http://www.w3schools.com/tags/ref_entities.asp

    Your DOMDocument is complaining as it has detected an invalid character definition on the way in, and corrected it on the way out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For one of my projects, I'm using the DOMDocument class to load and manipulate
I'm using PHP's DOMDocument to parse and normalize user-submitted HTML using the loadHTML method
I'm trying to cleanup some bad html using DOMDocument. The html has an <div
I need to load some arbitrary HTML into an existing DOMDocument tree. Previous answers
I'm using domdocument load to fetch some data. On occasion, this data is not
I'm reading some XML with PHP and currently using the DOMDocument class to do
I'm using a WebBrowser control in design mode. webBrowser1.DocumentText = <html><body></body></html>; doc = webBrowser1.Document.DomDocument
$content = file_get_contents(http://www.domain.com/page.html); $dom = new DOMDocument(); if (!@$dom->loadHTML($content)) die (Couldn't load file?); $title
I'm using XSLT to extract some HTML content with special characters (like &nbsp; )
I am using the loadhtml function ( http://php.net/manual/en/domdocument.loadhtml.phpt ) to load up an external

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.