Scooby08 Posted February 17, 2009 Share Posted February 17, 2009 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;?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/145504-heredoc-help/ Share on other sites More sharing options...
Philip Posted February 17, 2009 Share Posted February 17, 2009 <?php $test = "value"; echo <<<EOF <script language="JavaScript" type="text/JavaScript"> <!-- some javascript --> </script> <form> <input type="text" value="$test" /> </form> EOF; ?> Works just fine - outputs the correct code in the page source Quote Link to comment https://forums.phpfreaks.com/topic/145504-heredoc-help/#findComment-763927 Share on other sites More sharing options...
Philip Posted February 17, 2009 Share Posted February 17, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/145504-heredoc-help/#findComment-763929 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.