Go Back   CP Web Hosting - reseller hosting > Server Scripting > PHP
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-21-2007, 12:16 PM
Junior Member
 
Join Date: May 2007
Posts: 19
Default Strings enclosed in Single or Double Quotation

Strings in PHP can be enclosed between the double quotation marks (") or single quotation marks ('). Where is the different in it.
Reply With Quote
  #2 (permalink)  
Old 06-21-2007, 12:19 PM
Junior Member
 
Join Date: Apr 2007
Posts: 5
Default

There is a difference between double quotation marks and single quotation marks when used with strings.

Double quotation marks allow the parsing of variables. If you include a variable within double quotation marks the PHP engine substitutes the variable's value, like so:

$name = "Jim";
print "hello, $name"; // hello, Jim


If you use single quotation marks to enclose the same string, the variable is not substituted:



print 'hello, $name'; // hello, $name


Double-quoted strings are also parsed for escape characters. Escape characters take on or lose special meaning when preceded by a backslash (\) character. Notable among these are \n for a newline character, \t for a tab, \" to print a double-quoted character within a double-quoted string, \\ to print a backslash, and \$ to print a dollar sign (so that it is not mistaken for the start of a variable).

As a rule of thumb, if you want a string to be output exactly as you typed it, you can use single quotation marks. This can help your code to run more quickly because the interpreter does not have to parse the string. If you want to take advantage of escape characters such as \n and use variable substitution, you should use double quotation marks.
Reply With Quote
Reply


Thread Tools
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 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0