Connecting Tech Pros Worldwide Help | Site Map

new DomElement and Ampersand(&) in string

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 02:15 PM
petermichaux@yahoo.com
Guest
 
Posts: n/a
Default new DomElement and Ampersand(&) in string

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, 02:15 PM
petermichaux@yahoo.com
Guest
 
Posts: n/a
Default 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, 02:15 PM
Ken Robinson
Guest
 
Posts: n/a
Default 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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.