开发者

Syntax error on closing brace after opening a php tag

开发者 https://www.devze.com 2023-01-18 13:38 出处:网络
i\'m getting trouble with a function that looks pretty much like this: <?php function my_function() {

i'm getting trouble with a function that looks pretty much like this:

<?php 
function my_function() {

    if(!empty($variable)) {
        //Do some stuff
    }
    else {
        ?>show a message<?php 
    }
}
?>

The problem is i'm getting a parse error:

Parse error: syntax error, unexpected ‘}’ in /www/bla/bla/bla.php on line 8

I know for a fact that i'm not missing or have an extra '}' brace because the code works just fine on my local server and i've run a validator to make sure the syntax is correct, however, when i port the code to the online server, i get the error.

I believe it has something to do with the php installation not supporting the closing and reopening of php tags between the condition but i'm not sure how would i go about fixing it.

I know i could just do echo 'message'; instead, but this is not the only place where the script uses that kind of syntax to display messages, so fixing it here would just mean i'd get the 开发者_JS百科error on another line, and then another.

Thanks.


As it stands that piece of code runs just fine as is on PHP 5.2.14.

When you pasted in the code are you sure you pasted this line exactly as-is?:

?>show a message<?php

The only thing I can think of is that the code on the server is using a short open tag <? but SHORT_OPEN_TAG is turned off in the server's php.ini, for example :

?>show a message<?


I had a similiar issue with my file. This was throwing an error in my file:

<?php } ?> 

This may seem silly, I added a comment which seemed to fix the error:

<?php 
  //
  }
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号