Page 1 of 1

PHP parse error unexpected $end

Posted: Wed Apr 27, 2011 6:17 pm
by dave3009
Hi, first post here, thanks for looking

I was getting an error in PHP whereby I had written some PHP code for page content into my database when queried to the relevent page the php wasn't working. To get round this I used

Code: Select all

<?php eval('?>'.$page_content.'<?php'); ?>
which worked fabulously on WAMP, so I went on my merry way building my site. I then uploaded all the files on a web server, created the same table etc and now all I get is an error

[text]Parse error: syntax error, unexpected $end in /home/server/public_html/thesite/index.php(43) : eval()'d code on line 4[/text]

If I remove the eval code bit and echo the $page_content the error goes but none of the php within the content taken from the database works, it's just written as undisplayed text on the source. I've checked for missing braces, brackets, parenthesis etc as well as semicolons, double quotes and single quotes.....none seem present and this did work flawlessly on WAMP.

Is there any other way round this?

Re: PHP parse error unexpected $end

Posted: Wed Apr 27, 2011 8:05 pm
by fugix
why do you include php tags in this function?

Re: PHP parse error unexpected $end

Posted: Thu Apr 28, 2011 12:29 pm
by califdon
That error invariably means that you have unmatched 'container' elements, such as (, {, ;, etc., so that when the parser reaches the end of the script, some block is still open, thus the end is 'unexpected'. If it's a long script, it may be hard to find, but believe me, it's there. One way to find it is to comment out LARGE blocks of code and isolate where the problem is.

Re: PHP parse error unexpected $end

Posted: Fri Apr 29, 2011 1:05 pm
by dave3009
Thanks

I managed to sort it out by taking out the open php element at the end of the eval().

Code: Select all

<?php eval('?>'.$page_content); ?>
According to my reading these were supposed to be in there for 'good practice', on reflection this wasn't the case for me. I poured over the code time and time again to look for misplaced or superfluous }, {, ;, ), ( but found nothing, all the pages are stored in database tables but I took the time to test each page as a dedicated standalone .php file on it's own merit and had no errors. Everything now works perfectly, hopefully this will be another option for others to try in future.

Thanks for the help, thanks for looking

:D