note 39194 deleted from language.variables by cmb

From: Date: Mon, 05 Nov 2018 12:52:01 +0000
Subject: note 39194 deleted from language.variables by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209624@lists.php.net to get a copy of this message
Note Submitter: webmaster at daersys dot net ---- You don't necessarily have to escape the dollar-sign before a variable if you want to output its 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

« previous php.notes (#209624) next »