new DomElement and Ampersand(&) in string

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I'm trying the following code (ultimately I want a node with a URI like


$foo = new DomElement('foo','foo&bar');


and get the following error message

TEXT: unterminated entity reference             bar
LOCATION: /users/peter/store/index.php, line 3, at July 16, 2005, 9:35
Showing backtrace:
DOMElement.__construct("foo", "foo&bar") # line    3, file:

I cannot find a way to escape the ampersand so that the DomElement
constructor will take it as a character. I tried &amp; which is no
different, I tried \& which is no different.


Re: new DomElement and Ampersand(&) in string

I'm not sure what happened but now &amp; is working.

When appending '&Login' to the end of a uri that already contains some
ampersands I also have to play a trick where i replace any existing
ampersands with '&amp;' before appending '&amp;Login' and then create
the document element.

Re: new DomElement and Ampersand(&) in string wrote:
Quoted text here. Click to load it

Try writing your code like this:

   $foo = new DomElement('foo','foo&amp;bar');

The "&amp;" will get translated to an "&" when it's used.


Site Timeline