解析错误:语法错误,if()中的意外“{”

时间:2012-08-27 10:43:31

标签: php syntax

我收到Parse错误:语法错误,意外'{'

这是我的代码(用于wordpress评论循环)

<?php 
if (current_user_can('edit_comment',$comment->comment_ID)) { ?>
    <a href="<?php echo get_edit_comment_link(); ?>" title="Edit Comment">
        <img src="<?php echo get_template_directory_uri();?>/images/edit-link.png"/>
    </a>
<?php } ?>

3 个答案:

答案 0 :(得分:0)

尝试:

<?php if (current_user_can('edit_comment',$comment->comment_ID)) : ?>
    <a href="<?php echo get_edit_comment_link(); ?>" title="Edit Comment">
        <img src="<?php echo get_template_directory_uri();?>/images/edit-link.png"/>
    </a>
<?php endif;?>

答案 1 :(得分:0)

我是一次坚持使用一种语言的忠实粉丝。上下文切换令人困惑。

<?php

if (current_user_can('edit_comment',$comment->comment_ID)) {
    printf( "<a href='%s' title='Edit Comment'><img src='%s/images/edit-link.php'/></a>",
      get_edit_comment_link(),
      get_template_directory_uri()
    );
}

?>

虽然这是个人偏好,但我不会在您的问题中看到任何技术问题。

答案 2 :(得分:-1)

试试这个

<?php 
if (current_user_can('edit_comment',$comment->comment_ID)) { 
   echo "<a href=\"get_edit_comment_link()\" title=\"Edit Comment\">
        <img src=\"get_template_directory_uri()/images/edit-link.png\"/>
    </a>";
 } ?>

为什么不呢

<?php $a=get_edit_comment_link(); $b=get_template_directory_uri();
if (current_user_can('edit_comment',$comment->comment_ID)) {
   echo "<a href=\"$a\" title=\"Edit Comment\">
        <img src=\"$b/images/edit-link.png\"/>
    </a>";
 } ?>