new DomElement and Ampersand(&) in string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • petermichaux@yahoo.com

    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.__co nstruct("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

  • petermichaux@yahoo.com

    #2
    Re: new DomElement and Ampersand(&amp; ) 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.

    Comment

    • Ken Robinson

      #3
      Re: new DomElement and Ampersand(&amp; ) in string



      petermichaux@ya hoo.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

      Comment

      Working...