473,372 Members | 1,539 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,372 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 12139
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.