homepage Welcome to WebmasterWorld Guest from 54.234.128.25
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Quotes Inside Quotes
Very interesting, Did you know this?
Anyango




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

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




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

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




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved