I am quite new to php. This code is not working and shows error at the last line <html> <head><title>Example of here document: HTML embedded inside PHP script</title></head> <body> <?php $name = "Joe Smith"; $occupation = "Programmer"; echo <<<EOF This is a heredoc section. For more information talk to $name, your local $occupation. Thanks! EOF; $toprint = <<<EOF Hey $name! You can actually assign the heredoc section to a variable! EOF; echo strtolower($toprint); ?> </body> </html> Can anyone please tell me where the problem is? I think code is right, may be some header file is required for here document.
Works fine for me. Outputs <html> <head><title>Example of here document: HTML embedded inside PHP script</title></head> <body> This is a heredoc section. For more information talk to Joe Smith, your local Programmer. Thanks! hey joe smith! you can actually assign the heredoc section to a variable! </body> </html> HTML: What is the error you are getting?
First of all thanks for having the concern I tried to run the code in apache server. The browser shows something like " unable to resolve line no 26" which happens to be the last tag ie </html>
Exact error is Parse error: parse error in H:\EasyPHP 3.0\www\learningPHP5\Chap1\Examples\heredoc.php on line 26 Please help me find where the problem lies
<html> <head><title>Example of here document: HTML embedded inside PHP script</title></head> <body> <?php $name = "Joe Smith"; $occupation = "Programmer"; echo "<pre> This is a heredoc section. For more information talk to $name, your local $occupation. Thanks!"; $toprint = " Hey $name! You can actually assign the heredoc section to a variable! </pre>"; echo strtolower($toprint); ?> </body> </html> PHP:
Still the same problem is occurring. If the solved code is working well on your server, may be problem is somewhere else. I presumed that header file might be needed. Or am I missing some required step to execute the code? I am using EasyPHP 3.0 package
use WAMP 2 server.. it contains apache + mysql + php + sqlite etc.. just open it and then place your script in www folder the run the script. and see if you still get errors..
Yes, code runs on Wampserver. Thanks a lot for taking time to solve the problem. Thanks once again buddy
I was trying to find out what went wrong with the previous PHP 3.0 package. I came to arrive at interesting conclusion and the problem was with indenting END; closing identifier for here document. When I remove any space before END; code runs well otherwise it gives parse error. This is little bis strange for me as I have read php takes care of multiple spaces.