1

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.

3
  • are you actually using @_@ as a placeholder? that might be setting it off. Commented Feb 18, 2011 at 23:09
  • 2
    I don't see why @_@web_site_address@_@ should force an error, there must be wrong something else. You should look out for an ampersand, I'm pretty sure that you'll find the error there. Commented Feb 18, 2011 at 23:13
  • As I mentioned, I'm create a template system with place holders and if I put something which is not real URL I get exception... Commented Feb 19, 2011 at 23:51

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Believe me that part causes error, for instance try to put <a href="#holder#">Foo &nbsp Bar</a> and to load it in HTML error will occurs. Looks like I have to change the parsing way for my entire system :(
3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.