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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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;
?>
ASKER
that is why my example use $var .= 2 times.