Parser Error with Double Quotes

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

    Parser Error with Double Quotes


    Hi all,
    I am new to PHP programming.

    When I started with small examples of PHP, i landed with such errors
    which make me feel annoying.

    Incase of this snippet
    ---------
    06 <?php
    07 echo "Click here to see information about my favorite movie!";
    08 echo "</a>";
    09 ?>
    -----------------------------------

    the following error occurs..

    Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in
    C:\Program Files\xampp\htd ocs\movie1.php on line 7

    But while i replace the double quotes with single; everything works
    perfectly..

    Please comment on this.

    Regards,
    madan

  • Geoff Berrow

    #2
    Re: Parser Error with Double Quotes

    Message-ID: <1144568848.874 348.153970@g10g 2000cwb.googleg roups.com> from
    SharkHunter contained the following:
    [color=blue]
    >Incase of this snippet
    >---------
    >06 <?php
    >07 echo "Click here to see information about my favorite movie!";
    >08 echo "</a>";
    >09 ?>[/color]

    What's in the lines above?

    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • SharkHunter

      #3
      Re: Parser Error with Double Quotes

      The complete file would be

      <html>
      <head>
      <TITLE>Find my Favorite Movie!</TITLE>
      </head>
      <body>
      <?php
      echo "Click here to see information about my favorite movie!";
      echo "</a>";
      ?>
      </body>
      </html>

      Thanks

      Comment

      • Geoff Berrow

        #4
        Re: Parser Error with Double Quotes

        Message-ID: <1144571725.079 727.135950@u72g 2000cwu.googleg roups.com> from
        SharkHunter contained the following:
        [color=blue]
        ><html>
        ><head>
        ><TITLE>Find my Favorite Movie!</TITLE>
        ></head>
        ><body>
        ><?php
        >echo "Click here to see information about my favorite movie!";
        >echo "</a>";
        >?>
        ></body>
        ></html>[/color]

        Nothing wrong with that. I think you have missed out the bit that as
        causing the error.

        I suspect your original script looked like this:


        <?php
        echo "<a href="somepage. php" >Click here to see information about my
        favorite movie!";
        echo "</a>";
        ?>

        The quotes in the anchor tag need to be escaped (ie preceded by a
        backslash like so \" ) or replaced with single quotes.

        Having said that, there is no need for double quotes unless the echoed
        part contains a variable which you want to expand. Therefore using
        single quotes is fine. e.g.

        <?php
        echo '<a href="somepage. php" >Click here to see information about my
        favorite movie!';
        echo '</a>';
        ?>

        --
        Geoff Berrow (put thecat out to email)
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        • SharkHunter

          #5
          Re: Parser Error with Double Quotes

          Thanks Anyway, I have solved it.
          The prpblem is that i have copied these examples from the pdf. so the
          Double quotes used in the pdf are not being parsed by PHP.

          So this solves. it.

          Thanks.
          Madan

          Comment

          • SharkHunter

            #6
            Re: Parser Error with Double Quotes

            Thanks a lot for your reply..
            But the problem was with myself trying the code as per the pdf.

            Regards,
            Madan

            Comment

            Working...