PHP parse error unexpected $end

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dave3009
Forum Newbie
Posts: 2
Joined: Wed Apr 27, 2011 5:47 pm

PHP parse error unexpected $end

Post 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?
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: PHP parse error unexpected $end

Post by fugix »

why do you include php tags in this function?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP parse error unexpected $end

Post 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.
dave3009
Forum Newbie
Posts: 2
Joined: Wed Apr 27, 2011 5:47 pm

Re: PHP parse error unexpected $end

Post 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
Post Reply