473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

difference between ' and "

Today I spent a couple of hours searching for a bug, until I finally
found out that the problems was the following:

Correct: $path_upload = "$path/$file";

Instead of:

Wrong: $path_upload = '$path/$file';

Note a difference in quotation marks. Since I have been programming in
PHP I found out that there is very little difference between ' and ",
but is there somebody who can explain me, when to use ' and when to
use ". It would be really great if there is somebody to explain this
to me!

Thanks,
Jochem
Jul 17 '05 #1
10 12141
Jochem wrote:
Since I have been programming in
PHP I found out that there is very little difference between ' and ",
but is there somebody who can explain me, when to use ' and when to
use ". It would be really great if there is somebody to explain this
to me!


*NEVER* use ", unless you _need_ them

I only need " for two things:
embedding \n, \t and similar
simplify SQL queries, but I don't have to like it :)

$name1 = 'Pedro Graca'; // ok
$name2 = "Pedro Graca"; // forces PHP to do extra work
$name3 = $name1; // ok
$name4 = "$name2"; // UGH! *TRIPLE* UGH!!!!
// people who do this should be whipped
echo 'Your name is: ', $name, "<br/>\n";

$sql = "insert into table values($new_id, '$new_name')";
// for comparison here is the echo with only " (simpler, but not needed)
// echo "Your name is: $name<br/>\n";

// and the $sql with only ' (more awkward)
// $sql = 'insert into table values(' . $new_id . ', \'' . $new_name . '\')';
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
On 2003-12-30, Jochem <jd******@operamail.com> wrote:
Today I spent a couple of hours searching for a bug, until I finally
found out that the problems was the following:

Correct: $path_upload = "$path/$file";

Instead of:

Wrong: $path_upload = '$path/$file';

Note a difference in quotation marks. Since I have been programming in
PHP I found out that there is very little difference between ' and ",
but is there somebody who can explain me, when to use ' and when to
use ". It would be really great if there is somebody to explain this
to me!

http://www.php.net/manual/en/language.types.string.php

--
verum ipsum factum
Jul 17 '05 #3
On 2003-12-30, Pedro Graca <he****@hotpop.com> wrote:
$name4 = "$name2"; // UGH! *TRIPLE* UGH!!!!
// people who do this should be whipped
I think people only come up with this one if they have a Bash background
;)
// for comparison here is the echo with only " (simpler, but not needed)
// echo "Your name is: $name<br/>\n";


In this case you would need: "Your name is: {$name}<br>\n";

--
verum ipsum factum
Jul 17 '05 #4
Jochem wrote:
Today I spent a couple of hours searching for a bug, until I finally
found out that the problems was the following:

Correct: $path_upload = "$path/$file";

Instead of:

Wrong: $path_upload = '$path/$file';

Note a difference in quotation marks. Since I have been programming in
PHP I found out that there is very little difference between ' and ",
but is there somebody who can explain me, when to use ' and when to
use ". It would be really great if there is somebody to explain this
to me!


Main difference to me is that when using "" php is looking for variables
between the "".

- D -
Jul 17 '05 #5
Tim Van Wassenhove wrote:
On 2003-12-30, Pedro Graca <he****@hotpop.com> wrote:
$name4 = "$name2"; // UGH! *TRIPLE* UGH!!!!
// people who do this should be whipped


I think people only come up with this one if they have a Bash
background ;)
// for comparison here is the echo with only " (simpler, but not
needed) // echo "Your name is: $name<br/>\n";


In this case you would need: "Your name is: {$name}<br>\n";


Actually no,
echo "Some variable is $somevar dude!"; is perfectly fine. You only need { }
for arrays inside a string, e.g.
echo "Some variable is {$somevar['name']} dude!";
although inside of a string you can leave off the quotes on the key and have
echo "Some variable is $somevar[name] dude!";
While the last is proper according to the manual, I find it poor form and
prefer "somevar is {$something['blah']}".
Jul 17 '05 #6
On 2003-12-30, Agelmar <if**********@comcast.net> wrote:
Tim Van Wassenhove wrote:
On 2003-12-30, Pedro Graca <he****@hotpop.com> wrote:
$name4 = "$name2"; // UGH! *TRIPLE* UGH!!!!
// people who do this should be whipped
I think people only come up with this one if they have a Bash
background ;)
// for comparison here is the echo with only " (simpler, but not
needed) // echo "Your name is: $name<br/>\n";


In this case you would need: "Your name is: {$name}<br>\n";


Actually no,
echo "Some variable is $somevar dude!"; is perfectly fine. You only need { }
for arrays inside a string, e.g.


Actually yes, the OP wrote: echo "Your name is: $name<br/>\n";
No space between the variable and <br>.
echo "Some variable is {$somevar['name']} dude!";
although inside of a string you can leave off the quotes on the key and have
echo "Some variable is $somevar[name] dude!";
While the last is proper according to the manual, I find it poor form and
prefer "somevar is {$something['blah']}".


Not using quotes is not only poor, it is also slower.
--
verum ipsum factum
Jul 17 '05 #7
Tim Van Wassenhove wrote:
Actually yes,
Actually no. SCNR. ;-)
the OP wrote: echo "Your name is: $name<br/>\n";
No space between the variable and <br>.


A LESS-THAN SIGN, just like a SPACE, isn't a valid variable name
character, so the variable $name will be recognised.

http://www.php.net/manual/en/language.variables.php

--
Jock
Jul 17 '05 #8
In message <bs***********@ID-203069.news.uni-berlin.de>, Pedro Graca
<he****@hotpop.com> writes
<snip>

$name1 = 'Pedro Graca'; // ok
$name2 = "Pedro Graca"; // forces PHP to do extra work

<snip>

Could you explain why the double quotes make PHP do more work than the
single quotes, please?

--
Five Cats
Email to: cats_spam at uk2 dot net
Jul 17 '05 #9
Five Cats uttered the immortal words:
<snip>

$name1 = 'Pedro Graca'; // ok
$name2 = "Pedro Graca"; // forces PHP to do extra work

<snip>

Could you explain why the double quotes make PHP do more work than the
single quotes, please?


Click the link Tim posted in his first post to this thread.

--
Andy.
Jul 17 '05 #10
"Five Cats" <ca*******@[127.0.0.1]> wrote in message
news:Wv**************@[127.0.0.1]...
In message <bs***********@ID-203069.news.uni-berlin.de>, Pedro Graca
<he****@hotpop.com> writes
<snip>

$name1 = 'Pedro Graca'; // ok
$name2 = "Pedro Graca"; // forces PHP to do extra work

<snip>

Could you explain why the double quotes make PHP do more work than the
single quotes, please?

--
Five Cats
Email to: cats_spam at uk2 dot net


Bottom line: PHP parses anything in " " looking for variables to replace
with values, anything in ' ' it does not.


Jul 17 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: dpr | last post by:
I have come accross a piece of C++ code with the construct: MyClass *c = new class MyClass(); Is there a difference between this and: MyClass *c = new MyClass(); ?
7
by: Ollej Reemt | last post by:
Hello, I would like to know if there is a difference in c++ between the following two method-declarations: void Method(); and void Method(void);
8
by: Lian | last post by:
Hi all, It is a newbie's question about html tag "img". The attributes "title" and "alt" for "img" seems having the same function. So what is the main difference between them? Can i use them at...
3
by: Fei Li | last post by:
Hi, take string class as an example, who can explain the difference? Thanks
5
by: Agnes | last post by:
For my own practices. I like to put "Me". e.g IF Me.txtInvoice.textlength = 0 ....... etc Me.txt.....etc However, Is there any difference (without Me) ?? Thanks
6
by: John Pass | last post by:
What is the difference between a While and Do While/Loop repetition structure. If they is no difference (as it seems) why do both exist?
59
by: Rico | last post by:
Hello, I have an application that I'm converting to Access 2003 and SQL Server 2005 Express. The application uses extensive use of DAO and the SEEK method on indexes. I'm having an issue when...
3
by: Bsr | last post by:
What is the difference between for the following methods. "GET", "HEAD", "PUT" or "POST". Ex:my $req =HTTP::Request->new(GET =>$url1); Bhuvan.
6
by: =?Utf-8?B?SmVmZg==?= | last post by:
I thought this would already be covered here, but my search turned up nothing. In VS2005, if I use "String" to define a new variable/class, it colors it in the Aqua color as it does other...
2
brettl
by: brettl | last post by:
Hey all. I'm not sure if this question should be posted here or in the XML forums. Please forgive me if its in the wrong place or feel free to move it. Any who, I'm using a SOAP service to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.