Stats: 3,186,763 members, 7,930,631 topics. Date: Sunday, 25 August 2024 at 12:09 AM |
Nairaland Forum / Science/Technology / Programming / Single Vs Double Quotes In PHP (987 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)
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: 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: 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: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: 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: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)
Mql4 Programming. Lets Meet Here.... / Please Help On Userinterface And Userexperience / This Thread Goes To All Nairaland Programmers And Internet Gurus
(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. 18 |