Welcome to WebmasterWorld Guest from 50.17.78.238

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Quotes Inside Quotes

Very interesting, Did you know this?

     

Anyango

6:46 am on Feb 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Everyone knows that Single quotes will work inside double quotes and double quotes will work inside single quotes but do many people know this will work too ?


$test=array();
$test["title"]="Testing 123";
echo "Title is {$test["title"]}. See it works!";


Emphasis is not on the ability to use an array value inside quotation marks, but on the quotation marks themselves. Did you know this ?

coopster

2:07 pm on Feb 17, 2011 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Yes, I did, and use it quite often! Except my programming preference is to use single quotes around literal values in my array indexes ;)

I have my IDE set up so that the vars stand out in different color text and this form of syntax works great, especially in HEREDOC. I even use class methods within the HEREDOC with this syntax. For example, lets say the $date variable is an instance of a class for handling date functions, like adding the english ordinal suffix "th" to the current day "17" to display as "17th":
require_once 'class/DateFunctions.php'; 
$date = new DateFunctions();
$month = date('M');
$day = date('j');
$output = <<<EOT
<table>
<tr>
<td>Date:</td>
<td>{$month} {$day}{$date->getEnglishOrdinalSuffix($day)}</td>
</tr>
</table>
EOT;
print $output;

This and more can be found in the online PHP manual under Strings [php.net].

rocknbil

7:29 pm on Feb 17, 2011 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



It's still nowhere as usable as Perl's qq//; :-) It's the one thing I really miss in PHP.