By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,991 Members | 1,911 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,991 IT Pros & Developers. It's quick & easy.

Difference between quotation and apostrophe in PHP

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.