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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.