Apr 23, 2006
My Digital Life Editorial Team

PHP Parse Error: syntax error, unexpected $end

In PHP 5, the following error may appears as an error entry in Apache error log or simply displays on PHP web page, even if calling to php scripts with php_info() works perfectly and successfully returns information on PHP configurations:

Parse Error: syntax error, unexpected $end in ….. scripts.php on line …

The error may caused by a missing curly bracket in PHP script coding. Beside, it may also caused by error in PHP coding in class definition, as in PHP, a class definition cannot be broke up and distributed into multiple files, or into multiple PHP blocks, unless the break is within a method declaration.

But more commonly, the error is often caused by the use of Short Open tags in PHP,

To use short open tags, it must be enabled in PHP.INI. Search for short_open_tag in PHP.INI, and change the value to On. The line should look line:

short_open_tag = On

  • Praneet Sah

    Thanks a lot I spent more than 2 days about searching for solution to this error! Really thanks a ton mate! You saved my PC to be thrown at the wall!! :P

  • saurabh

    thanx :)

  • Shalzers

    Thanks, this fixed a huge snafu for me.

  • Tadej

    Thankyou for this post! saved me a lot of time!

  • six

    Man, you saved my day :D. Tnx

  • vishal

    thanks , it helped me lot….

  • Mohammad Jolani

    Thank for good help.

  • http://www.inquestor.org Adam Walton

    Hey,

    I had the same error response “PHP Parse Error: syntax error, unexpected $end”. The thing was my code was perfect, everything. I was so puzzled.

    I found the answer and figured I would care it will the community:)

    Turns out PHP parses ?> even in comments.
    Example: // If query has characters like /?>|`,. ect remove them

    That was one of my comments but I fixed it with the following
    /* If query has characters like /?>|`,. ect remove them */

    Anyway like I said somebody might find this comment useful. I spend an hours going through my code.

    Peace!

    /* If query has characters like /?>|`,. ect remove them

  • danesa

    thank u ! great help ..

  • rp

    it should be in everyone’s best practice to put <?php instead of <? in all your code.

  • Nick F

    Thanks, this solved a very puzzling problem for me!

  • Ela

    Thanks a lot, it also worked for me ..:)

  • pavan

    good..

  • Jakob Stoeck

    Didn't know that the error does also come up for short tags when they aren't allowed. Thanks!

  • Dedi

    THANKS MAN…..

    You r smart….and honest :)

  • Deon

    Thanks for this – it was a missing curly bracket for me :)

  • Ben

    Thanks man …..

    you saved my lot of time….

    Thank u very much and keep posting

  • http://lisainc.org ncole

    this error

    syntax error, unexpected $end in /home/lisainc/public_html/StitchTogether/includes/application_top.php on line 21

    the line 21 is

    {

    exit('Server Requirement Error: register_globals is disabled in your PHP configuration. This

    can you help?

  • giriayoga

    thank you for your tutorial

  • Rodney

    Thanks for the post. The short_open_tag response solved a problem for me.

  • Dan

    Terrific

    This is clearly an oldie but a goodie

    You've just helped me out no end

    Thanks !

  • http://twitter.com/kurko Alexandre de Oliveir

    3 years later, I found the real problem. Somewhere in the code is written %>, like in a table .

    If your asp_tags = On, in ASP it means closing. It's amongst your HTML code. I got many hours to solve this problem.

  • Neha

    Thanks Buddy your information helped me from hell of headache(spcly whn the code is not written by youself and u have to make your changes into it..phewww)….but thanks your suggestions helped me to locate and remove errors…..making <? to <?php solved my prob..:)

  • Gregory Mlay

    Also, some Webserver does not support the tag <? for php files, change them to <?php and it can work. (Dar Es Salaam, Tanzania)

  • http://www.profzahoor.rwp.edu.pk Zahoor Ahmad

    It was very much helpful in solving my problem of the same kind of error.

  • http://Web hardy101

    Thank you for this awesome tip about short_open_tags! Would have never found that by myself.

  • COMALite J

    Rana, any source code editor that supports Find / Replace with Regular Expressions can help you balance braces.

    Example: in Macrodobe Dreamweaver (any non-absolutely-ancient version), do [Ctrl]+[F] to activate Find/Replace, tell it:

    Find in: Current Document

    Search: Source Code

    Find: [{}]

    Replace: (leave blank)

    Options: “Use Regular Expression” checked, all others unchecked.

    Then simply do Find Next. This will find both opening and closing braces. For each opening brace you find, count them starting at 1. For each closing brace, subtract 1 from the current count. You should wind up at 0 just before it wraps around back to the beginning (also in any specific function, block, etc.).

    E.g.

    <code>foreach ($array as $value) { // 1

    if ($value > 100) { // 2

    echo "$value too big!
    ";

    } // 1

    } // 0</code>

  • Raghavendra

    Thank you very much …..

  • Richard

    Thank you,

    Been searching for ages for solution to this.

    short_open_tag = On solved that problem for me.

    Finally I can open templates

  • sugi

    syntax error, unexpected $end in C:wampwwwlogin.php on line 49

  • http://codeproject.wordpress.com Rana

    Thanks for your time, But for me Its really didfficult to find a missing curly bracket.

    Is there any easiest way to findout with MISSING CURLY BRACKET. Any editor can do it for us.

    Please Help.

    Rana

  • Guy

    Very useful, thanks. I just upgraded to openSuse 10.3 from 10.2 which had reset my php.ini.

  • http://dibagroup.com Hamed

    wow! thanks for your useful guidance…

  • gilbert

    thhanx a lot short_open_tag = On solved my problem. ypu are helpful

  • Shawn

    Thanks a ton, I've been trying to figure this out for the last few hours.

  • phpcoder

    This might be due to a missing quote also

  • Bruno

    Hello. I have a problem with a PHP file that shows the "PHP Parse Error: syntax error, unexpected $end" error and I followed the instructions in this page and corrected the php.ini from OFF to ON.

    Now, the file don't give any feedback when I open it. It only gives me a blank page and no info! O_o

    It's strange… Can you help me please? Thanks.

  • ike

    I saw your posting and made the change to the php.ini file and I'm still getting the error the is being run with Fedora Core 5 with MySql 5.

    Can someone please help

    0)

    {

    while ($row = mysql_fetch_assoc($result))

    {

    print $row('cust_id') . '-' . $row('cust_url_desc') ;

    }

    }

    else

    {

    echo 'No rows found!';

    }

    mysql_free_result($result);

    mysql_close($connection);

    ?>

  • Paul

    Thanks for this post…saved me a lot of time!

  • http://drwael.homeip.net drwael

    thanks a lot,

    short_open_tag = On solved that problem for me