PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Difference between quotation and apostrophe in PHP
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Difference between quotation and apostrophe in PHP

Réponse
 
LinkBack Outils de la discussion
Vieux 18/12/2007, 10h50   #1
Royan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.
  Réponse avec citation
Vieux 18/12/2007, 11h39   #2
Toby A Inkster
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Difference between quotation and apostrophe in PHP

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/
  Réponse avec citation
Vieux 18/12/2007, 11h51   #3
Gordon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Difference between quotation and apostrophe in PHP

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.
  Réponse avec citation
Vieux 18/12/2007, 12h33   #4
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Difference between quotation and apostrophe in PHP

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h57.


Édité par : vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12501 seconds with 12 queries