John,

PHP looks for "$vars or {$vars} to parse in the string" when double quotes
are used... whereas when single quotes are used, it won't parse/substitute
the vars.

<?
// works:
echo "My favourite fruit is {$fruit}";
echo "My favourite fruit is $fruit";
echo 'My favourite fruit is '.$fruit;

// doesn't work:
echo 'My favourite fruit is {$fruit}';
echo 'My favourite fruit is $fruit';
?>

So, when you're not using $vars, using single quotes will be marginally
faster... perhaps not important on small sites, but very important on big
ones, and a decent habbit to get into :)


Justin


on 15/12/02 12:30 PM, John Taylor-Johnston
([EMAIL PROTECTED]) wrote:

> Marco (or anyone)
> 
> What is the difference between:
> $familyname = getvar("familyname");
> and
> $familyname = getvar('familyname');
> 
> What do single quotes do, as a general rule, that double cannot (he asks
> remembering something, but not sure what)?
> 
> 
> 
> 
> Marco Tabini wrote:
> 
>> I haven't followed the rest of the thread, but how about using a
>> function?
>> 
>> function getvar ($varname)
>> {
>> if (isset ($_POST[$varname])
>> {
>> $_SESSION[$varname] = $_POST[$varname];
>> return $_POST[$varname];
>> }
>> elseif (isset ($_SESSION[$varname]))
>> return $_SESSION[$varname];
>> }
>> 
>> session_start();
>> 
>> // You don't need session_register anymore
>> 
>> $familyname = getvar('familyname');
>> 
>> and so on--just one line per variable.
>> 
>> Hope this helps.
>> 
>> Cheers,
>> 
>> Marco
>> --
>> ------------
>> php|architect - The Magazine for PHP Professionals
>> The monthly magazine dedicated to the world of PHP programming
>> 
>> Check us out on the web at http://www.phparch.com!
>> 
>> -----------------------------------------------------------------------------
>> -----------------------------------------------------------------------------
>> -----------------------------------------------------------------------------
>> -----------------------------------------------------------------------------
>> -----------------------------------------------------------------------------
>> -----------------------------------------------------------------------------
>> -----------------------------------------------------------------------------
>> -----------------------------------------------------------------------------
>> -----------------------------------------------------------------------------
>> -----------------------------------------------------------------------------
>> -----------------------------------------------------------------------------
>> ----------------------------------------------------
>> 
>> Subject: [PHP] Session: I RTFM
>> Date: Sat, 14 Dec 2002 18:41:40 -0500
>> From: John Taylor-Johnston <[EMAIL PROTECTED]>
>> Reply-To: [EMAIL PROTECTED]
>> Organization: FLSH, U-de-S
>> To: [EMAIL PROTECTED]
>> 
>>> Jason wrote:
>>> RTFM again.
>> 
>> Jason, again, I RTFM, but did not get it working.
>> Otherwise I wouldn't have dared ask a question.
>> 
>>> Sessions depends on a number of factors
>>> including your version of PHP and the setting of register_globals.
>> 
>> The FM manual says:
>> 
>> "$_SESSION (or $HTTP_SESSION_VARS with PHP 4.0.6 or less) is recommended"
>> 
>> So I am using "PHP Version 4.1.2" (and "4.2.3" on my localhost to test
>> offline)
>> 
>> Ok. I quit using $HTTP_POST_VARS["familyname"].
>> 
>> With a little rethinking, I have this working, I hope.
>> 
>> Now ... is there a cleaner way to assign my variable "familyname"?
>> 
>> Pseudo code:
>> 
>> if _post["familyname"] exists set session variable
>> (no sense in setting it until I post it)
>> if _session["familyname"] exists, $familyname = $_SESSION["familyname"];
>> 
>> I'll have about 30 variables. Going to be alot of lines. There must be an
>> easier, cleaner way?
>> 
>> <?php
>> #session_name("TestALS");
>> session_start();
>> 
>> if (isset($_POST["familyname"]))
>> {
>> session_register("familyname");
>> $familyname = $_POST["familyname"];
>> echo "Yay: \$familyname= $familyname<br>";
>> }
>> 
>> if (isset($_SESSION["familyname"]))
>> {
>> $familyname = $_SESSION["familyname"];
>> echo "yay session works, \$familyname= $familyname<br>";
>> }
>> 
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> --
> John Taylor-Johnston
> -----------------------------------------------------------------------------
> "If it's not open-source, it's Murphy's Law."
> 
> ' ' '   Collège de Sherbrooke:
> ô¿ô   http://www.collegesherbrooke.qc.ca/languesmodernes/
> -     Université de Sherbrooke:
> http://compcanlit.ca/
> 819-569-2064
> 
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

Justin French
--------------------
http://Indent.com.au
Web Development & 
Graphic Design
--------------------


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to