if-else 块中的解析错误 Unexpected }

Parse error Unexpected } in if-else block

我已经在 SO 上搜索了一个多小时,但无法解决我的问题。由于某种原因,第 262 行中的页面出现解析错误:语法错误意外}。它是 else 条件的右括号。

我去掉else条件,代码运行顺利。然后我恢复并删除了 else 条件下的所有内容,但错误仍然相同,我很困惑为什么右括号是意外的。

这是代码

if(isset($_POST['sendEmailNotification'])){

$keyword = $_POST['sendEmailNotification'];
$sql = "SELECT * FROM team where keyword = '$keyword'" ;
$sql_result = mysqli_query($conn,$sql) or die (mysqli_error($conn));
while ($row = mysqli_fetch_assoc($sql_result)){
    $abcd = $row; 
} 

$htmlContent = file_get_contents ("email_template_header.php"); 
$registerURL = $siteURL.'/register/';

if ($abcd['claimed'] == 1) {

    $htmlContent .= "<p>Hey,</p>";
    $htmlContent .= "<p>Hope you're doing well!!!</p>";
    $htmlContent .= "<p>Someone has submitted an image related to your business on www.trustedbusiness.reviews. He/She might be your customer or may be your employee/ex-employee.</p>";
    $htmlContent .= "<p>You can approve the image just by following these simple steps:</p>";
    $htmlContent .= "<ol>";
    $htmlContent .= "<li>View Business Center</li>";
    $htmlContent .= "<li>Click on Business Name</li>";
    $htmlContent .= "<li>Select 'Image' option from sidebar</li>";
    $htmlContent .= "<li>Approve the 'Image' & you're done</li>";
    $htmlContent .= "</ol>";
    $htmlContent .= "<p>If you need any help or have any suggestions to make the User Experience better. Please feel free to contact Trusted Business Reviews team.</p>";
    $htmlContent .= "<p>Thanks</p>";

}
else {

    $htmlContent .= "<p>Hey,</p>";
    $htmlContent .= "<p>Hope you're doing well!!!</p>";
    $htmlContent .= "<p>Someone has submitted an image related to your business on www.trustedbusiness.reviews. He/She might be your customer or maybe your employee/ex-employee.</p>";
    $htmlContent .= "<p>Uh-oh!</p>";
    $htmlContent .= "<p>You haven't claimed your business on Trusted Business Reviews? No problem!</p>";
    $htmlContent .= "<p>You can claim this by following these simple & super easy steps:</p>";
    $htmlContent .= "<ol>";
    $htmlContent .= "<li>Register here</li>";
    $htmlContent .= "<li>Open your Business Listing Page</li>";
    $htmlContent .= "<li>Click on 'Claim This Business'</li>";
    $htmlContent .= "<li>Enter your domain email address</li>";
    $htmlContent .= "<li>Enter Verification Code</li>";
    $htmlContent .= "<li>You're Done</li>";

    $htmlContent .= "</ol>";
    $htmlContent .= "<p>You can make the desired changes in the information (if needed) after 'claim this business' process.</p>";
    $htmlContent .= "<p>Later, You can approve the image just by following these simple steps:</p>";
    $htmlContent .= "<ol>";
    $htmlContent .= "<li>View Business Center</li>";
    $htmlContent .= "<li>Click on Business Name</li>";
    $htmlContent .= "<li>Select 'Image' option from sidebar</li>";
    $htmlContent .= "<li>Approve the 'Image' & you're done</li>";
    $htmlContent .= "</ol>";
    $htmlContent .= "<p>If you need any help or have any suggestions to make the User Experience better. Please feel free to contact Trusted Business Reviews team.</p>";
    $htmlContent .= "<p>Thanks</p>";
}
$htmlContent .= file_get_contents ("email_template_footer.php"); 
$to = $abcd['b_email'];

require 'PHPMailerAutoload.php';

$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->SMTPAuth = false;
$mail->SMTPSecure = 'tls';
$mail->Port = 25;
$mail->setFrom('abc@mail.com', 'ABC');
$mail->addAddress($to);
$mail->isHTML(true);
$mail->Subject = 'New Image Uploaded';
$mail->Body = $htmlContent;
$mail->send();
$mail->clearAddresses();
}

积分不足,无法作为可能的答案发表评论:

当我的代码(就像你的)没问题时,我感到很神秘 "parse errors"。

在我的情况下,这是由我的 PC (OS/browser?) 在从网页复制和粘贴示例代码时以某种方式插入的虚假隐藏字符引起的。

例如else {

如果"else"和“{”之间的"space"实际上不是"space"那么它可能会导致后面的{被忽略。结果:else语句提前终止 即 else $htmlContent .= "<p>Hey,</p>"; 其余的连接将被视为 else 块之外的语句,并且关闭的“}”将被视为无效。

尝试删除您的 else 子句并手动重​​新输入。

如果这不起作用,请在设置为显示隐藏字符的编辑器中打开您的代码。在 HTML 套件中(我认为)view->editor->hidden characters 将显示这些字符为纯黑色而不是 space 的纯白色。