Jump to content

[SOLVED] HEREDOC syntax


Voodoo Jai

Recommended Posts

Hi all again

Wow this forum is fantastic I only wish I could be of more help than a pest.

 

Here we go again, I got some help with a previous post which suggested this type of code

 

<?php
$A = 4;
if ($A == 4) 
{
$x = "number (first variable)";

$takeaway=<<<EDOC
<table border="1">
    <tr>
    <td valign="top">
<div align="left">
<span class="style5">
Free phone
</span>						
</div>
</td>
    <td valign="top">
<div align="left">
$x
</div>
</td>
    </tr>
</table>
EDOC;
echo $takeaway;
}
?>

 

I have since found some more references to this type of code and come up with this

 

<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;

/* More complex example, with variables. */
class foo
{
   var $foo;
   var $bar;

   function foo()
   {
       $this->foo = 'Foo';
       $this->bar = array('Bar1', 'Bar2', 'Bar3');
   }
}

$foo = new foo();
$name = 'MyName';

echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[0]}.
This should print a capital 'A': \x41 <br>
EOT;
echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital 'A': \x41 <br>
EOT;
echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[2]}.
This should print a capital 'A': \x41
EOT;
?> 

 

What I want to know is! is it Ok to repeat the code with the same identifier or should I use different identifier names.

 

Thanks again

Jai

Link to comment
https://forums.phpfreaks.com/topic/83635-solved-heredoc-syntax/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.