My Notepad

  • My Linux Notes
  • My Grid Notes
  • To do List
  • Sunday, December 11, 2005

     
    The single and double quotation marks in PHP

    One of the most annoying stuffs in PHP for a newbie like me is the use of single quotation marks ' and double quotation marks''. When should I use ' or for "?
    Here's a example,

    $id = 1;
    $ok1 = @mysql_query("DELETE from Authors where ID=$id");

    We can only use '' here , because only the variables quoted within '' can be interpreted by PHP.If we replace '' by ' , then the actual value we passed in the query will be '$id', not 1.

    Lets see another example,

    In this echo clause, we the variables $name, $id need to be interpreted by PHP, therefore we can't use sigle quotation, because PHP won't interpret variables inside signle quotation marks.
  • However, we also notice that the two $id are indeed quoted within single qoatation marks, so will they be interpreted by PHP?
    The answer is yes.It seems like the we can use '' and ' together when we need nested quotations,and PHP will still interpret the varibles inside single quotions marks if they are within outer double quotions marks.
  • you can also see this from ,



  • Comments: Post a Comment



    << Home

    Archives

    December 2005   January 2006   February 2006   April 2006   May 2006   June 2006   July 2006   November 2006   February 2007   May 2007   June 2007   November 2007   February 2008   March 2008   April 2008   August 2008   December 2008   March 2009   April 2009   May 2009   June 2009   October 2009   November 2009   December 2009   May 2013  

    This page is powered by Blogger. Isn't yours?