Connecting Tech Pros Worldwide Help | Site Map

new DomElement and Ampersand(&) in string

  #1  
Old July 17th, 2005, 03:15 PM
petermichaux@yahoo.com
Guest
 
Posts: n/a
Hi,

I'm trying the following code (ultimately I want a node with a URI like
index.php?foo=1&bar)

<?php

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

?>

and get the following error message

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



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.

Thanks,
Peter

  #2  
Old July 17th, 2005, 03:15 PM
petermichaux@yahoo.com
Guest
 
Posts: n/a

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.

  #3  
Old July 17th, 2005, 03:15 PM
Ken Robinson
Guest
 
Posts: n/a

re: new DomElement and Ampersand(&) in string




petermichaux@yahoo.com wrote:[color=blue]
> Hi,
>
> I'm trying the following code (ultimately I want a node with a URI like
> index.php?foo=1&bar)
>
> <?php
>
> $foo = new DomElement('foo','foo&bar');
>
> ?>[/color]

Try writing your code like this:

<?php
$foo = new DomElement('foo','foo&amp;bar');
?>

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

Ken

Closed Thread