jadedknight Posted January 27, 2008 Share Posted January 27, 2008 I have seen examples (specifically in the book 'Learning PHP 5') of a heredoc inside a function, however when I attempt the same thing, I get an error: Parse error: syntax error, unexpected $end in PATH\add_note.php on line 26 The error, I presume is because the PHP document is ending but the function? Or something else is not. Here is the code I am using. <?php function print_form() { print <<< FORM <form action="addnote_validate.php" method="post"> <label for="title">Title</label> <input type="text" id="title" name="title" /> <label for="url">Related URL <span>(optional)</span></label> <input type="text" id="url" name="url" /> <label for="content">Note</label> <input type="text" id="note" name="note" /> <label for="tags">Tags <span>(seperated with a space)</span></label> <input type="text" id="tags" name="tags" /> <input type="submit" value="Save Note"/> </form> FORM; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87986-solved-php-heredoc-inside-a-function-not-working/ Share on other sites More sharing options...
pocobueno1388 Posted January 27, 2008 Share Posted January 27, 2008 The code works fine for me. Make sure there are no trailering spaces after the FORM; line. Quote Link to comment https://forums.phpfreaks.com/topic/87986-solved-php-heredoc-inside-a-function-not-working/#findComment-450184 Share on other sites More sharing options...
jadedknight Posted January 27, 2008 Author Share Posted January 27, 2008 Here is a screenshot of my exact code. ??? Weird... [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/87986-solved-php-heredoc-inside-a-function-not-working/#findComment-450190 Share on other sites More sharing options...
KrisNz Posted January 27, 2008 Share Posted January 27, 2008 There mustn't be any white space or any other character for that matter on either side of the end delimiter for a heredoc string. Quote Link to comment https://forums.phpfreaks.com/topic/87986-solved-php-heredoc-inside-a-function-not-working/#findComment-450192 Share on other sites More sharing options...
jadedknight Posted January 27, 2008 Author Share Posted January 27, 2008 Actually, one more issue, now I get a different error. Parse error: syntax error, unexpected T_SL in PATH\add_note.php on line 5 Quote Link to comment https://forums.phpfreaks.com/topic/87986-solved-php-heredoc-inside-a-function-not-working/#findComment-450193 Share on other sites More sharing options...
jadedknight Posted January 27, 2008 Author Share Posted January 27, 2008 Haha.. XD Nevermind! All solved, thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/87986-solved-php-heredoc-inside-a-function-not-working/#findComment-450196 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.