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


19 Responses to “PHP Parse Error: syntax error, unexpected $end”

  1. Alexandre de Oliveira
    October 29th, 2009 22:19
    19

    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.

  2. Neha
    October 3rd, 2009 17:59
    18

    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. Gregory Mlay
    July 9th, 2009 14:15
    17

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

  4. Zahoor Ahmad
    January 25th, 2009 12:42
    16

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

  5. hardy101
    December 11th, 2008 11:26
    15

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

  6. COMALite J
    September 12th, 2008 23:57
    14

    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.
    foreach ($array as $value) { // 1
    if ($value > 100) { // 2
    echo "$value too big!\n";
    } // 1
    } // 0

  7. Raghavendra
    May 10th, 2008 14:10
    13

    Thank you very much …..

  8. Richard
    March 17th, 2008 00:32
    12

    Thank you,

    Been searching for ages for solution to this.

    short_open_tag = On solved that problem for me.

    Finally I can open templates

  9. sugi
    March 8th, 2008 14:27
    11

    syntax error, unexpected $end in C:\wamp\www\login.php on line 49

  10. Rana
    February 27th, 2008 20:22
    10

    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

  11. Guy
    October 23rd, 2007 18:52
    9

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

  12. Hamed
    September 30th, 2007 12:07
    8

    wow! thanks for your useful guidance…

  13. gilbert
    September 15th, 2007 20:20
    7

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

  14. Shawn
    August 30th, 2007 19:39
    6

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

  15. phpcoder
    March 29th, 2007 22:29
    5

    This might be due to a missing quote also

  16. Bruno
    February 5th, 2007 07:41
    4

    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.

  17. ike
    December 20th, 2006 04:57
    3

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

    ?>

  18. Paul
    August 22nd, 2006 22:49
    2

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

  19. drwael
    May 14th, 2006 23:30
    1

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

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feature has been disabled. To receive notification of latest comments posted, subscribe to My Digital Life Comments RSS feed or register to receive new comments in daily email digest.
Custom Search

New Articles

Incoming Search Terms for the Article

Parse error: syntax error, unexpected $end - php unexpected $end - Parse error: syntax error, unexpected $end in - unexpected $end php - syntax error, unexpected $end - php unexpected end - Parse error: syntax error, unexpected $end in - Parse error: syntax error, unexpected $end - PHP Parse error: syntax error, unexpected $end - parse error syntax error unexpected end in php - php Parse error: syntax error, unexpected $end - unexpected end php - syntax error, unexpected $end in - syntax error, unexpected $end - PHP Parse error: syntax error, unexpected $end in - unexpected end in php - syntax error unexpected end in php - unexpected $end in php - PHP Parse error: syntax error, unexpected $end in - $end php - php unexpected $end - php $end - php unexpected $end in - Parse error: syntax error, unexpected $end - php "unexpected $end" - unexpected $end - parse error syntax error unexpected end in - syntax error, unexpected $end php - PHP Parse error: syntax error, unexpected $end in - php Parse error: syntax error, unexpected $end - syntax error, unexpected $end in php - $end php error - Parse error: syntax error, unexpected $end in php - PHP Parse error: syntax error, unexpected $end in Command line code on line 1 - unexpected $end php - Parse error: syntax error, unexpected $end i - php error unexpected $end - php unexpected end in - php Parse error: syntax error, unexpected $end in - unexpected end error in php - arse error: syntax error, unexpected $end in - wordpress Parse error: syntax error, unexpected $end in - php error $end - $end error in PHP - Parse error: syntax error, unexpected $end in - Parse error: parse error, unexpected $end - "Parse error: syntax error, unexpected $end" - arse error: syntax error, unexpected $end - "Parse error: syntax error, unexpected $end in" - unexpected #end php -