Link to home
Start Free TrialLog in
Avatar of DingDang
DingDang

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DingDang
DingDang

ASKER

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.
sorry my mistake, it should have thre < instead of my typo of two.
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