Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,147,987 members, 7,799,388 topics. Date: Tuesday, 16 April 2024 at 08:14 PM

Single Vs Double Quotes In PHP - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Single Vs Double Quotes In PHP (956 Views)

Online Banking Source Code In PHP, MSQL / How Can I Build A Twitter like @mention System In PHP? / Simple CRUD Application In PHP And Mysql (2) (3) (4)

(1) (Reply) (Go Down)

Single Vs Double Quotes In PHP by maekhel(m): 11:54am On Jan 06, 2015
Today we will be taking a quick look at Single vs Double Quotes In PHP. This is going to be a very brief tutorial. Most people (myself inclusive) misuse this quotes. Now that I understand where and when they are being used, I decided to share it with you guys.
The Single Quotes (”)
The single quotes will not interpret the value of the variables enclosed in them. The single quotes will output the string as they are without any interpretation. Let demonstrate this with example:

//let declare a variable and assign value to it
$variable = "Tutorialslodge";
echo 'This lesson is from $variable';
When the code snippets above is executed, it will out put: This lesson is from $variable. This is to show that the single quotes will display whatever it contains as it is.
The Double Quotes (“”)
The Double Quotes unlike the Single Quotes will not only output values but also interpret any variables it contains. Let use the same example from above to demonstrate Double Quotes:

//let declare a variable and assign value to it
$variable = "Tutorialslodge";
echo "This lesson is from $variable";
When this code is executed, the PHP HyperText Preprocessor will parse the $variable in the double quotes and replace it with the value which that variable holds. So our code will output: This lesson is from Tutorialslodge.
So you now know when and where to use each of the quotes. Remember if you want your variables to be interpreted, use Double Quotes, hence use Single Quotes.
I hope this tutorial is helpful. Kindly drop your comments, questions, suggestions and views in the box below.
source: http://tutorialslodge.com/single-vs-double-quotes-php/
Re: Single Vs Double Quotes In PHP by blenyo11(m): 12:07pm On Jan 06, 2015
This is a good one. I have never noticed this
Re: Single Vs Double Quotes In PHP by maekhel(m): 1:51pm On Jan 06, 2015
blenyo11:
This is a good one. I have never noticed this
it happens...thats why no one is an island of knowledge
Re: Single Vs Double Quotes In PHP by tobyemmanuel(m): 2:49pm On Jan 07, 2015
Very wrong. Try this out
[quote]//let declare a variable and assign value
to it
$variable = "Tutorialslodge";
echo 'This lesson is from '.$variable.' ';[\quote]
Re: Single Vs Double Quotes In PHP by codemarshal08(m): 6:54pm On Jan 07, 2015
tobyemmanuel:
Very wrong. Try this out

HEy , What he said is true. Moreover the example you sited is very different from what meakhel illustrated in his first post.

NOTE: Am not an expert. I believe we are all here to learn !
Re: Single Vs Double Quotes In PHP by maekhel(m): 8:35pm On Jan 07, 2015
tobyemmanuel:
Very wrong. Try this out
your code is way different from mine. you didn't quote $variable, you only concatenated it to the quoted string.
Re: Single Vs Double Quotes In PHP by wolexme(m): 7:09pm On Jan 09, 2015
// a workaround
$wrk = 'work it around';
echo 'we can{$wrk} for single quotes'; //we can work it around for single quotes

(1) (Reply)

Is This True? (pics) / I Need Enlightening From Experts / 3 Simple Tricks That Will Help You Make More Sales On Your Website

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 12
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.