Mr Chris Posted June 13, 2009 Share Posted June 13, 2009 Hello, I'm trying to put together a function but am getting the message: Parse error: syntax error, unexpected $end at the end of the function. I know this normally happens when the { and } don't match up, but unless i'm going bonkers they do? Any ideas? Thanks <? function FuncName() { $total = 0; $output = '<form action="" method="post"> <input type="hidden" name="aaa" value="bbb"> <input type="hidden" name="fff" value="1"> <input type="hidden" name="ddd" value="666666k">'; foreach ($this->Cart as $ProductID => $Qty){ $result = $Database->query('SELECT * FROM books WHERE id = '.$ProductID); $row = $result->fetch(); $price = sprintf('£%.2f', $row['price']); $rowTotal = sprintf('£%.2f', $row['price'] * $Qty); $total += $row['price'] * $Qty; $output .= <<<ROW <input type="hidden" name="one_{$ProductID}" value="{$description}"> <input type="hidden" name="two_{$ProductID}" value="{$rowTotal}"> <input type="hidden" name="three_{$ProductID}" value="{$Qty}"> ROW; } $total = sprintf('£%.2f', $total); $output .= <<<END <input type="submit" value="Submit"> </form> END; return $output; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/162059-solved-parse-error-on-a-function/ Share on other sites More sharing options...
rivan Posted June 13, 2009 Share Posted June 13, 2009 It looks to me there is some error with heredoc strings you are using (in fact you have one closing brace too much but something with heredocs make php parser go wild) Quote Link to comment https://forums.phpfreaks.com/topic/162059-solved-parse-error-on-a-function/#findComment-855137 Share on other sites More sharing options...
Mark Baker Posted June 13, 2009 Share Posted June 13, 2009 IIRC, ROW; should be ROW; i.e. the ROW; to terminate the heredoc must be the very first characters in the line, no white space or anything is permitted. edit - added warning quoted from the PHP manual It is very important to note that the line with the closing identifier must contain no other characters, except possibly a semicolon (. That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including Mac OS X. The closing delimiter (possibly followed by a semicolon) must also be followed by a newline. Quote Link to comment https://forums.phpfreaks.com/topic/162059-solved-parse-error-on-a-function/#findComment-855138 Share on other sites More sharing options...
rivan Posted June 13, 2009 Share Posted June 13, 2009 also mentioned above NO SPACES AFTER ; in heredoc end (you have spaces there too, very difficult to spot ) Quote Link to comment https://forums.phpfreaks.com/topic/162059-solved-parse-error-on-a-function/#findComment-855143 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.