473,382 Members | 1,204 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,382 software developers and data experts.

Difference between quotation and apostrophe in PHP

Difference between quotation and apostrophe in PHP

I wonder is there any difference between strings wrapped into
quotation marks or into apostrophes and if so is there any situation
when one is preferable to the other?
-R.
Dec 18 '07 #1
3 8090
On Dec 18, 9:50 am, Royan <romayan...@gmail.comwrote:
Difference between quotation and apostrophe in PHP

I wonder is there any difference between strings wrapped into
quotation marks or into apostrophes and if so is there any situation
when one is preferable to the other?
-R.
The difference is that you can use variables directly in double quoted
strings.

Try this, for example.

<?php

$rand = mt_rand (1, 1000000);

echo ('The random number value is $rand<br />');
echo ("The random number value is $rand<br />");

You can also use \n in a double quoted string to insert a newline, \t
to insert a tab, etc. You can't do this with single quoted strings.

This doesn't mean that single quoted strings are inferior. They don't
have the overhead associated with variable insertion so if you're
doing huge amounts of string manipulation then single quoted is
faster. Also, you don't have to escape the " character in single
quoted strings, and given that attributes in HTML and XML are meant to
be surrounded by " characters this can be a quite significant
advantage.
Dec 18 '07 #2
Royan wrote:
I wonder is there any difference between strings wrapped into quotation
marks or into apostrophes and if so is there any situation when one is
preferable to the other?
<?php

$greeting = 'Hello';

echo "$greeting World\n";
echo '$greeting World\n';

// Run this and note the difference.

?>

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 10 days, 21:14.]

Sharing Music with Apple iTunes
http://tobyinkster.co.uk/blog/2007/1...tunes-sharing/
Dec 18 '07 #3
On 18 Dec, 09:50, Royan <romayan...@gmail.comwrote:
Difference between quotation and apostrophe in PHP

I wonder is there any difference between strings wrapped into
quotation marks or into apostrophes and if so is there any situation
when one is preferable to the other?
-R.
But you didn't wonder quite enough to type:
php single double quote
into Google huh?

http://uk3.php.net/manual/en/language.types.string.php
Dec 18 '07 #4

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

Similar topics

3
by: James Foreman | last post by:
I've got a set of emails in a table, where sometimes they've failed to input the @ properly. Eg james.foreman'abcmail.co.uk How do I write a replace to deal with that? Also, I've got a set...
13
by: Richard Hollenbeck | last post by:
To prevent future apostrophe bugs and errors, isn't it just simpler to forbid an apostrophe from being entered into a text field? For example, couldn't "Alice's Restaurant" be changed to "Alices...
9
by: M P | last post by:
Hi! I am looking for a way that I can trap the single quotation mark. If an encoder uses single quotation mark on a textbox field, it always give me an error because I use single quotes on the...
2
by: VB Programmer | last post by:
In my dev environment the single quote/apostrophe shows up fine. When I publish the site all the single quotes are missing. Any ideas why? Is there a special character I have to use for the...
9
by: dajava | last post by:
Hi, Sorry for this beginner's question. I do not know PHP and write for my friend. He has never been a professional programmer. He studied C and PHP with some books and made a bulletin...
31
by: The Bicycling Guitarist | last post by:
Hi. For many years I have been using &quot; for double quotation marks in the HTML code, but the opening and closing quotation marks render the same in my browser. I'm considering going through and...
9
by: Thomas 'PointedEars' Lahn | last post by:
Jukka K. Korpela wrote: IBTD. For example, in English it is customary (and AIUI expected) to use the character that ’ represents should be used to delimit a quotation within direct speech...
3
by: Alan Mailer | last post by:
Ok, I've looked for an answer for this, because I'm sure it's been asked a thousand times... but no luck... so here goes. Imagine I want to create a NodeList based on an XPath statement. The...
3
by: Aisya | last post by:
Hye, I need help to overcome the problem mention above. My application needs user to key in their details, but when it comes to name some names has an apostrophe, somehow it's okay to save the...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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.