Jump to content

Recommended Posts

Could somebody let me know if this is the correct way to do this? It seems like it's not right because the closing javascript tag seems to escape the <<<EOF..

 

<?php
$test = "value";

return <<<EOF
<script language="JavaScript" type="text/JavaScript">
<!--
some javascript
-->
</script>
<form>
<input type="text" value="$test" />
</form>
EOF;
}
?>

 

Would I want the input line to be like it is, or like this:

 

<input type="text" value="<?=$test;?>" />

 

Link to comment
https://forums.phpfreaks.com/topic/145504-heredoc-help/
Share on other sites

In regards to your edit:

 

You don't need to do <?php ?> tags, because heredoc is a type of string and will parse variables automatically. See the example on the php.net page:

 

<?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[1]}.
This should print a capital 'A': \x41
EOT;
?>

 

Will output:

My name is "MyName". I am printing some Foo.

Now, I am printing some Bar2.

This should print a capital 'A': A

Link to comment
https://forums.phpfreaks.com/topic/145504-heredoc-help/#findComment-763929
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.