|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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/ |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Dec 18, 9:50 am, Royan <romayan...@gmail.com> wrote:
> 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. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On 18 Dec, 09:50, Royan <romayan...@gmail.com> wrote:
> 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 |
|
![]() |
| Outils de la discussion | |
|
|