Voodoo Jai Posted December 29, 2007 Share Posted December 29, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/83635-solved-heredoc-syntax/ Share on other sites More sharing options...
pocobueno1388 Posted December 29, 2007 Share Posted December 29, 2007 It doesn't matter as long as you start it and end it, then the name is ready to be used again. Quote Link to comment https://forums.phpfreaks.com/topic/83635-solved-heredoc-syntax/#findComment-425452 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.