Something like $var .= qq~Text~; (from Perl) in PHP?

hi,

i'm a seasonal perl coder. i'm sooo use to this style of conding in Perl :

$var .=qq~ "put whatever output here" without worrying to escape the "inverted coma" ~;
$var .=qq~ and i really miss this function now.. nowhere to find in PHP :( ~;

and just print $var; wherever i want for the output, and it will look like this :

"put whatever output here" without worrying to escape the "inverted coma" and i really miss this function now.. nowhere to find in PHP :(

question : how can i possibly do this with PHP? echo<<<code "something" code; can accomplish this, but it doesn't assign it to variable like qq does.
DingDangAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
maybe you are interested in the HEREDOC string notation:
http://lu.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc


$str = <<<EOD
put whatever output here" without worrying to escape the "inverted coma" 
and i really miss this function now.. nowhere to find in PHP 
EOD;
echo $str;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DingDangAuthor Commented:
thats quite like it, but it seems can be use with $var = and not $var .= (dot equal). .= enable me to collect and add values into the existing variable along the way, so at the end i can just puke the $var with all collected values.

that is why my example use $var .= 2 times.
0
DingDangAuthor Commented:
sorry my mistake, it should have thre < instead of my typo of two.
0
v2MediaCommented:
You can concatenate additional string data to a var using heredoc syntax.
<?php
 
$myVar = '';
 
$myVar .= <<<EOD
<p class="highlight">One paragraph</p>
EOD;
 
$myVar .= '<p>Another paragraph</p>';
 
$myVar .= <<<EOD
<p class="highlight">Two paragraph</p>
EOD;
 
echo $myVar;
 
?>

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.