PHP Parse Error: syntax error, unexpected $end

ยปยปยป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, <? instead of full tag, <?php in PHP scripts. Both tags can be used, although for good practice, it’s recommended to use only the full tags <?php when programming in PHP scripts, especially in applications or libraries that are meant for redistribution, or deployment on PHP servers which are not under your control, because short tags may not be supported on the target server.

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

By | 2016-12-18T08:22:45+00:00 December 18th, 2016|Categories: Web Servers|Tags: |43 Comments

About the Author:

LK is a technology writer for Tech Journey with background of system and network administrator. He has be documenting his experiences in digital and technology world for over 15 years.

Connect with LK through Tech Journey on Facebook, Twitter or Google+.

  • thanks a lot,
    short_open_tag = On solved that problem for me

  • Paul

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

  • 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

    while ($row = mysql_fetch_assoc($result))
    print $row('cust_id') . '-' . $row('cust_url_desc') ;


    echo 'No rows found!';




  • 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.

  • phpcoder

    This might be due to a missing quote also

  • Shawn

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

  • gilbert

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

  • wow! thanks for your useful guidance…

  • Guy

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

  • 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.

  • sugi

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

  • 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

  • Raghavendra

    Thank you very much …..

  • 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.).

    <code>foreach ($array as $value) { // 1
    if ($value > 100) { // 2
    echo "$value too big!
    } // 1
    } // 0</code>

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

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

  • 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)

  • 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..:)

  • 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.

  • Dan


    This is clearly an oldie but a goodie

    You've just helped me out no end

    Thanks !

  • Rodney

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

  • giriayoga

    thank you for your tutorial

  • 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?

  • Ben

    Thanks man …..
    you saved my lot of time….

    Thank u very much and keep posting

  • Deon

    Thanks for this – it was a missing curly bracket for me ๐Ÿ™‚

  • Dedi


    You r smart….and honest ๐Ÿ™‚

  • Jakob Stoeck

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

  • pavan


  • Ela

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

  • Nick F

    Thanks, this solved a very puzzling problem for me!

  • rp

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

  • danesa

    thank u ! great help ..

  • 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.


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

  • Mohammad Jolani

    Thank for good help.

  • vishal

    thanks , it helped me lot….

  • six

    Man, you saved my day :D. Tnx

  • Tadej

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

  • Shalzers

    Thanks, this fixed a huge snafu for me.

  • saurabh

    thanx ๐Ÿ™‚

  • 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!! ๐Ÿ˜›

  • suresh

    Thanks. after adding this in php.ini it worked for me.

    short_open_tag = On

  • amzar mohamed

    please help with html

    syntax error, unexpected end of file in /home/u707205640/public_html/index.php on line 1931 why is this happend

  • Gusty Sapto Ady Prakoso

    Thanks veerrry verrry thankksss

Pin It on Pinterest

Share This

Share This

Share this post with your friends!