OM2 Posted July 26, 2008 Share Posted July 26, 2008 I've sumbled across PHP's heredoc, where you use: <<< (Thanks to other answers from earlier posts.) I've got a weird problem. This code works: [code<?php $imageGalleryString = <<<galleryString Test galleryString; echo $imageGalleryString; ?> But, this code doesn't: <?php $imageGalleryString = <<<galleryString Test galleryString; echo $imageGalleryString; ?> Erm: what am I missing!!? The ONLY difference is the tab before the edning of galleryString above. I've read PHP.net and it says that you can't have anything after the last line of your text other than a new character (or something like that). That's really weird. Why is this?? OM Quote Link to comment https://forums.phpfreaks.com/topic/116740-problem-with-heredoc/ Share on other sites More sharing options...
wildteen88 Posted July 26, 2008 Share Posted July 26, 2008 I don't see any difference between the two snippets. Quote Link to comment https://forums.phpfreaks.com/topic/116740-problem-with-heredoc/#findComment-600326 Share on other sites More sharing options...
OM2 Posted July 26, 2008 Author Share Posted July 26, 2008 hmmm... i think i must have cut and paste incorrectly. where you have: galleryString; if there is a space in front of it, then it doesnt work!! Quote Link to comment https://forums.phpfreaks.com/topic/116740-problem-with-heredoc/#findComment-600328 Share on other sites More sharing options...
MFHJoe Posted July 26, 2008 Share Posted July 26, 2008 From Wikipedia: The line containing the closing identifier must not contain any other characters; otherwise, it will not be considered to be a closing identifier, and PHP will continue looking for one. Quote Link to comment https://forums.phpfreaks.com/topic/116740-problem-with-heredoc/#findComment-600330 Share on other sites More sharing options...
OM2 Posted July 26, 2008 Author Share Posted July 26, 2008 thanks for the reply. that was my question: why is it like this? that seems really weird! i cant think of a good reason why they need to have this as a rule? Quote Link to comment https://forums.phpfreaks.com/topic/116740-problem-with-heredoc/#findComment-600335 Share on other sites More sharing options...
MFHJoe Posted July 26, 2008 Share Posted July 26, 2008 It's just how it works mate. It probably makes the PHP compiler slightly faster as it knows where it should be looking rather than scanning the whole line. Quote Link to comment https://forums.phpfreaks.com/topic/116740-problem-with-heredoc/#findComment-600336 Share on other sites More sharing options...
OM2 Posted July 26, 2008 Author Share Posted July 26, 2008 erm: no way...! i'm sorry, i cant let php get away with that. there *has* to be a good reason! Quote Link to comment https://forums.phpfreaks.com/topic/116740-problem-with-heredoc/#findComment-600341 Share on other sites More sharing options...
MFHJoe Posted July 26, 2008 Share Posted July 26, 2008 Good luck trying to find one . Quote Link to comment https://forums.phpfreaks.com/topic/116740-problem-with-heredoc/#findComment-600342 Share on other sites More sharing options...
wildteen88 Posted July 26, 2008 Share Posted July 26, 2008 I believe other languages abide by this rule, such as Perl. Its not just PHP. EDIT: A Heredoc article. Its pretty much a standard thing for the closing delimiter be on its own. Quote Link to comment https://forums.phpfreaks.com/topic/116740-problem-with-heredoc/#findComment-600347 Share on other sites More sharing options...
OM2 Posted July 26, 2008 Author Share Posted July 26, 2008 hmmm weird. it's like getting stuck trying to solve a problem and then coming up with a hack and sticking with it! Quote Link to comment https://forums.phpfreaks.com/topic/116740-problem-with-heredoc/#findComment-600349 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.