TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-30-2007, 08:51 PM   #1 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default How do you structure your quotes?

I like to make all strings with double quotes, and use single quotes for HTML tags. Quotation marks in strings are done with "

So, I structure my echo statements like so:

PHP Code:
echo "<p span='font-size=3em;'>Two is the number two.  You want to say too as in &quot me too &quot</p>"
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 12-30-2007, 08:58 PM   #2 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

For me personally, if it has a PHP variable in it, I'll use double-quotes, if not, single quotes. All SQL statements use double quotes.

eg:

PHP Code:
echo 'Hello World';

echo 
"Hello $firstname";

$sql "SELECT something FROM somewhere"
Edit: I also have a habbit of breaking out of strings for variables - eg:

PHP Code:
echo 'Hello ' $firstname ' Welcome to my site!'
So I generally only use double quotes for SQL statements

Alan

Last edited by Alan @ CIT : 12-30-2007 at 09:00 PM. Reason: added bit about breaking out of strings
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 12-30-2007, 09:19 PM   #3 (permalink)
dav
The Wanderer
 
dav's Avatar
 
Join Date: Dec 2007
Location: Manchester, UK
Posts: 9
Thanks: 1
dav is on a distinguished road
Default

I use single quote for everything I do in PHP and double quotes for my HTML attributes.
dav is offline  
Reply With Quote
Old 12-31-2007, 12:36 AM   #4 (permalink)
The Acquainted
Upcoming Programmer 
 
CMellor's Avatar
 
Join Date: Sep 2007
Location: Leeds, UK
Posts: 141
Thanks: 6
CMellor is on a distinguished road
Default

I use:

PHP Code:
echo('Hello my name is<strong>' .$name'</strong>'); 
__________________
Not quite a n00b...
CMellor is offline  
Reply With Quote
Old 12-31-2007, 02:58 AM   #5 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

Is that just a particular quirk, or does it seem more neat to you?
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 12-31-2007, 03:11 AM   #6 (permalink)
The Acquainted
Upcoming Programmer 
 
CMellor's Avatar
 
Join Date: Sep 2007
Location: Leeds, UK
Posts: 141
Thanks: 6
CMellor is on a distinguished road
Default

Me personally, it's about neatness. I'm a neat freak, even with my code. Having my variables outside of quotes, it colour codes it, meaning it's easier to spot.
__________________
Not quite a n00b...
CMellor is offline  
Reply With Quote
Old 12-31-2007, 03:46 AM   #7 (permalink)
The Acquainted
 
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
Andrew is on a distinguished road
Default

Also, with single quotes, the variables will be treated literally, so:
PHP Code:
$var 'hi';
echo 
'$var'// prints $var
echo "$var"// prints hi
echo 'hi'.$var.'hi'// prints hihihi 
Send a message via AIM to Andrew Send a message via MSN to Andrew
Andrew is offline  
Reply With Quote
Old 12-31-2007, 06:19 AM   #8 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

Yes, but the same goes for
PHP Code:
echo "\$var"
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 12-31-2007, 09:56 AM   #9 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

I agree with Chris on this - breaking out of strings for variables does look a lot neater to me (and my IDE's colour syntaxing) than having them inline.

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 12-31-2007, 05:16 PM   #10 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

I'm very anal about laying out of code. Pretty much all strings are wrapped in single quotes; concatenating strings and variables with single spaces between the string and variable, and variable and string (or two variables, or whatever). Basically:
PHP Code:
// Me likey
$string = 'This string is ' . $colour;

// Me no likey
$string = 'This string is '.$colour;
$string = 'This string is '. $colour;
$string = 'This string is ' .$colour;
$string = "This string is $colour";

// Evil!
$var = 'colour';
$string = "This string is ${$var}";

// Super Evil! Even worse than the above!!
$string = "This string is " . $colour;

Also, since there has been a fair amount of echoing concatenated strings in this topic: remember that you can separate expressions with a comma when using echo!
PHP Code:
echo 'This string is' . $colour;
echo 'This string is', $colour;

The latter (with commas) forgoes the overhead of first concatenating the elements together into one long (in relative terms) string then echoing it, in favour of outputting a series of smaller strings: the upshot being that it is marginally faster to process.
Salathe is offline  
Reply With Quote
Old 01-01-2008, 04:49 AM   #11 (permalink)
The Acquainted
Upcoming Programmer 
 
CMellor's Avatar
 
Join Date: Sep 2007
Location: Leeds, UK
Posts: 141
Thanks: 6
CMellor is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
Also, since there has been a fair amount of echoing concatenated strings in this topic: remember that you can separate expressions with a comma when using echo!
PHP Code:
echo 'This string is' . $colour;
echo 'This string is', $colour;
Cool, I never knew that
__________________
Not quite a n00b...
CMellor is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:53 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design