nrvncanada Posted December 29, 2009 Report Posted December 29, 2009 Hi, can anyone please give me complete working code for here document in PHP? Please do not give extracts of the example like <?php echo << Hi, I want an example of php here document. Not the extracts of php code, rather complete code. I mean starting with and ending with . Please put code only if you were able to interpret/ compile the code succussfully. END; ?> If you could provide the solution, I am thankful to you. Otherwise too thankful.... Just kidding Quote
falkencreative Posted December 29, 2009 Report Posted December 29, 2009 Looks like you are looking for "heredoc"... Here's a working example: $str = Example of string spanning multiple lines using heredoc syntax. EOD; echo $str; ?> If that isn't what you are looking for, you'll need to clarify what you need. More info: http://php.net/manual/en/language.types.string.php Quote
jlhaslip Posted December 29, 2009 Report Posted December 29, 2009 http://en.wikipedia.org/wiki/Here_document Quote
nrvncanada Posted December 30, 2009 Author Report Posted December 30, 2009 (edited) Edited December 30, 2009 by nrvncanada Quote
falkencreative Posted December 30, 2009 Report Posted December 30, 2009 I read all these example. I copied the example and embedded in html tags. But when I try to compile them parsing error occurs. Did your code interpret well? If yes please give me html embedded code. Post the code you are working with/what error you get, and I can take a look and see what the issues is. Quote
nrvncanada Posted December 31, 2009 Author Report Posted December 31, 2009 <?php $name = "Joe Smith"; $occupation = "Programmer"; echo << This is a heredoc section. For more information talk to $name, your local $occupation. Thanks! EOF; $toprint = << Hey $name! You can actually assign the heredoc section to a variable! EOF; echo strtolower($toprint); ?> Quote
nrvncanada Posted December 31, 2009 Author Report Posted December 31, 2009 Actually I was using EasyPHP 3.o package where the parsing problem occurred. I tried to run same code on Wamp Server and it runs. Thanks to all of you for taking time for me. Thanks a lot:D Quote
nrvncanada Posted January 12, 2010 Author Report Posted January 12, 2010 I was trying to find out where the actual problem was and I found very strange reason. If I try to add space before closing here document identifier END; parse error happens. Otherwise the code runs well. I did not find any explanation for that as PHP supports any no space to be included. Quote
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.
Note: Your post will require moderator approval before it will be visible.