note 39194 added to language.variables

From: Date: Tue, 20 Jan 2004 13:15:00 +0000
Subject: note 39194 added to language.variables
Groups: php.notes 
Request: Send a blank email to php-notes+get-63873@lists.php.net to get a copy of this message
In reference to "remco at clickbizz dot nl"'s note I would like to add that you don't necessarily have to escape the dollar-sign before a variable if you want to output it's name. You can use single quotes instead of double quotes, too. For instance: <?php $var = "test"; echo "$var"; // Will output the string "test" echo "\$var"; // Will output the string "$var" echo '$var'; // Will do the exact same thing as the previous line ?> Why? Well, the reason for this is that the PHP Parser will not attempt to parse strings encapsulated in single quotes (as opposed to strings within double quotes) and therefore outputs exactly what it's being fed with :) To output the value of a variable within a single-quote-encapsulated string you'll have to use something along the lines of the following code: <?php $var = 'test'; /* Using single quotes here seeing as I don't need the parser to actually parse the content of this variable but merely treat it as an ordinary string */ echo '$var = "' . $var . '"'; /* Will output: $var = "test" */ ?> HTH - Daerion ---- Manual Page -- http://www.php.net/manual/en/language.variables.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39194 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39194&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39194&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#63873) next »