vaske
vaske

Reputation: 9552

PHP: DOMDocument loadHTML returns error with nesty URL in href

Recently I get an exception while I try to implement a special template engine.

Mine problem with DOMDocument load is in fact that I use some place holders in href and it will be replaced after with real values. I want to store that template and to use it each time when I need it, here is code sample

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

And nesty part of HTML looks like

<a href="@_@web_site_address@_@">Visit our web site</a>

and exception is

Fatal error: DOMDocument::loadXML() [<a href='domdocument.loadxml'>domdocument.loadxml</a>]: EntityRef: expecting ';' in Entity

I was try to find a some way to skip that check but couldn't find anything.

Upvotes: 1

Views: 2878

Answers (2)

vaske
vaske

Reputation: 9552

I found what was the problem. In my URL it was & sign, I was replace it with &amp; and now it works.

Upvotes: 3

brianlmoon
brianlmoon

Reputation: 324

This causes no error in PHP 5.3. You must have some other HTML that is causing this. Normally you see this when you use an entity with no ; after it.

<a href="#">Foo &nbsp Bar</a>

That throws that same error for me. Look for some entity without a ; on it. Browsers will render that, but it is not correct.

Upvotes: 3

Related Questions