cbassett03 Posted July 18, 2012 Share Posted July 18, 2012 When using statements such as ECHO, or when setting a variable equal to a text value (Such as $name = "Joe") Should you use double quotes or a single quote? Is one better (or more secure) than the other? I've seen it done both ways in books and online (code examples). What is the standard (or generally accepted standard, if there is one) regarding this? Quote Link to comment Share on other sites More sharing options...
mattspriggs28 Posted July 18, 2012 Share Posted July 18, 2012 I tend to use single quotes, especially if I'm storing any html code in a variable as it means I don't have to escape every double quote. I'm not aware that one is any more secure than the other though, maybe someone else has an insight into this. Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 18, 2012 Share Posted July 18, 2012 A string in double quotes will be parsed. There is information about this in the manual. http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing If you don't have any variables within it, and especially if you plan to use double quotes like in HTML, use single quotes. If you plan to have apostrophes, or variables that you want to parse, use double quotes. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.