Forum Moderators: coopster

Message Too Old, No Replies

Parse error: syntax error, unexpected '}' in .

If possible, short term help, it's kind of urgent to protect income

         

Jim123

11:48 pm on Jan 26, 2011 (gmt 0)

10+ Year Member



I'm trying to protect some code with an expiration date but I get the same message whatever I do. It should be too hard, but I don't know how to solve it...

Anyone? Please...


<?
//set your link expiration date here.
$expiry = strtotime("8/12/2020");
$today = strtotime("now");

if ($today > $expiry) {



if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '<div class="wdtbt"></div></div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
}

if ( !is_admin() ) {
wp_deregister_script('jquery');
wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"), false, '1.3.2');
wp_enqueue_script('jquery');
};



} else { ?>
<?php } ?>

brotherhood of LAN

12:19 am on Jan 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The code you supplied parses OK on its own. I assume this code is part of a bigger script or is included by another file.

Typically that error means there is a missing complimentary bracket or there is a missing colon at the end of the statement.

The line number in the error should help a lot.

Jim123

6:54 am on Jan 27, 2011 (gmt 0)

10+ Year Member



Thanks for the reply. It's part of a file, but also with me it parses OK.

The error is in the second last line with 'else'.

The file is indeed included by another file. I guess it's a bit difficult to avoid the error, right?

rocknbil

6:35 pm on Jan 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One of the things that annoys me with WP is the way it drops in and out of PHP/HTML (annoys me because it's so hard to debug. :-) )

Unless you have some HTML encapsulated in these last two lines, you can change this

} else { ?>
<?php } ?>

to this

} else {
}
?>

Or, if it's truly empty, you can remove it entirely.

}
?>

leaving only the closing block for the If. I tend to agree with J.H. though, this code is more or less "ok" and it's probably some previous extra } that is cascading down to this chunk.

Jim123

10:38 pm on Jan 27, 2011 (gmt 0)

10+ Year Member



Still the error. You are right about WP, a simple thing like this is not even possible.

The error is still in the last }. I'll have to look for something else. Thanks for the reply

brotherhood of LAN

10:46 pm on Jan 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Since you're not getting the accurate line number (it must be an error further up... try working backwards, putting an exit(0); above code blocks and includes, retrying the script, until you no longer have the error. It'll give you a better idea of which area of all the included PHP is causing the hassle.

rocknbil

5:25 pm on Jan 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah but it will still error in compiling, won't it?

brotherhood of LAN

10:31 pm on Jan 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



True enough, I forgot to say 'remove the code below the exit' by commenting it out.

Jim123

2:43 am on Jan 29, 2011 (gmt 0)

10+ Year Member



About the error line number. This is always in the same line .

} else { ?>

rocknbil

9:46 pm on Jan 30, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Holy cow, I think it's been here all along. Did you modify this chunk at all? Let's break it down and observe. I added comments at each mark.

<?
//set your link expiration date here.
$expiry = strtotime("8/12/2020");
$today = strtotime("now");

if ($today > $expiry) { //opening today/expiry



if ( function_exists('register_sidebar') ) { //opening function exists
// removed register sidebar code
}//closing function exists

if ( !is_admin() ) { //opening ! is admin
// removed deregister, wp_register, wp_enqueue
}; //closing ! is admin and WHAT'S THIS?



} //closing today/expiry followed by the else
else { ?>
<?php } ?>

Look closely at the line preceding "WHAT'S THIS?"

Why is there a statement-closing semicolon there? It's not a nested function . . . try removing just that semicolon, like this.

if ( !is_admin() ) {
// removed deregister, wp_register, wp_enqueue
}

Jim123

11:24 pm on Jan 30, 2011 (gmt 0)

10+ Year Member



Yeah, you are right. That one shouldn't be there...

I removed some parts and ended up with this and still getting and error... I guess, since this file is included, there is another mistake somewhere else. Maybe I can send it to WP for them to look since it's one of them files?

The error is in line: } //closing today/expiry followed by the else

after bringing it back to

<?
//set your link expiration date here.
$expiry = strtotime("8/12/2020");
$today = strtotime("now");
if ($today > $expiry) { //opening today/expiry
} //closing today/expiry followed by the else
else { ?>
<?php } ?>


It's amazing that something simple like this is not possible with WP.

Matthew1980

8:21 am on Jan 31, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all,

Not saying as this will cause your error, BUT, consistency of defining a php document CAN make the script run erroneously:

<?php
//set your link expiration date here.
$expiry = strtotime("8/12/2020");
$today = strtotime("now");

I bang on about this a lot because I have seen this cause failure. <?php echo "hello"; ?> <<- this runs on any server config. This ->> <? echo "hello"; ?> wouldn't.

Well spotted Rocknbil! I don't think that in scripts this sort of size, that dropping in and out of php is the best method of practise, echo's would be better.

Cheers,
MRb

Jim123

11:38 pm on Feb 2, 2011 (gmt 0)

10+ Year Member



Sorry, still no luck yet. I don't think it's possible in Wordpress...

Thanks for all the help though.