what is wrong with this code?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kees

    what is wrong with this code?

    I was under the impression that the single quote ' did not interpret
    the content.

    prog 1
    <HTML>
    <BODY>
    <?PHP
    echo '"a"';
    ?>
    </BODY>
    </HTML>
    this gives as expected "a"

    prog 2
    <HTML>
    <BODY>
    <?PHP
    echo '"<a"';
    ?>
    </BODY>
    </HTML>
    I want "<a" but
    it gives "<a>
    So without the closing " but with a closing >

    Strange. What am I doing wrong?

    Greeting
    Kees



  • Ken Robinson

    #2
    Re: what is wrong with this code?


    Kees wrote:[color=blue]
    > prog 2
    > <HTML>
    > <BODY>
    > <?PHP
    > echo '"<a"';
    > ?>
    > </BODY>
    > </HTML>
    > I want "<a" but
    > it gives "<a>
    > So without the closing " but with a closing >
    >
    > Strange. What am I doing wrong?[/color]

    Try:

    <?
    echo '"&lt;a&gt;" ';
    ?>

    Ken

    Comment

    • John Dunlop

      #3
      Re: what is wrong with this code?

      Kees wrote:
      [color=blue]
      > prog 2
      > <HTML>
      > <BODY>
      > <?PHP
      > echo '"<a"';
      > ?>
      > </BODY>
      > </HTML>
      > I want "<a" but
      > it gives "<a>
      > So without the closing " but with a closing >[/color]

      No, that isn't the output. The output is exactly what you
      thought it should be; that is, "<a".

      However, browsers understand '<' to be the start of a tag if
      it is followed by a Name Start Character. A browser would
      then read the 'a' but get confused when it comes across '"',
      which isn't a valid Name character in HTML. It looks as
      though error recovery kicked in and everything up until the
      '>' of '</BODY>' was ignored. Thus, you were presented with
      "<a> by your web browser.

      When '<' comes immediately before a Name Start Character,
      such as 'a', it needs to be encoded, either with &lt;, &#60;
      or &#x3C;, if it is to be taken literally. The
      htmlspecialchar s function converts '<' to &lt;.



      --
      Jock

      Comment

      Working...