doujingxi3356 2019-02-10 07:14
浏览 35
已采纳

PHP解析错误:语法错误,[重复]中意外的“其他”(T_ELSE)

This question already has an answer here:

I have php code on my result page and I added some else to my php script, but i got error PHP Parse erro syntax error, unexpected else T_ELSE in / line 122

$domain_only = preg_split('/\./', $domain);

foreach($ext as $item){

    $domain = $domain_only[0].$item;

    if ( checkdnsrr($domain, 'ANY') ) {

        $response = '<tr id="com">
            <td>
                <i class="fa fa-times text-color-error"></i>
            </td>
            <td>
                <h4 class="text-color-error">'.$domain.'</h4>
            </td>
            <td class="text-color-error">Rp. 125.000</td>
            <td>
                <a class="button button-primary" href="https://www.indoip.com/whois/'.$domain.'" target="_blank" style="background: #cd3100">
                <i class="fa fa-eye icon-left"></i>Whois</a>
            </td>
        </tr>';
        }
line 122     else
        {
            //  =================================================
        $response = '<tr id="web.id">
            <td>
                <i class="fa fa-check text-color-success"></i>
            </td>
            <td>
                <h4>'.$domain.'</h4>
            </td>
            <td class="highlight">Rp. 55.000</td>
            <td>
            </td>
        </tr>';
    }
     else
        {
            //  =================================================
        $response = '<tr id="net">
            <td>
                <i class="fa fa-check text-color-success"></i>
            </td>
            <td>
                <h4>'.$domain.'</h4>
            </td>
            <td class="highlight">Rp. 93.000</td>
            <td>
            </td>
        </tr>';
    }
     else
        {
            //  =================================================
        $response = '<tr id="co.id">
            <td>
                <i class="fa fa-check text-color-success"></i>
            </td>
            <td>
                <h4>'.$domain.'</h4>
            </td>
            <td class="highlight">Rp. 80.000</td>
            <td>
            </td>
        </tr>';
    }
     else
        {
            //  =================================================
        $response = '<tr id="net.id">
            <td>
                <i class="fa fa-check text-color-success"></i>
            </td>
            <td>
                <h4>'.$domain.'</h4>
            </td>
            <td class="highlight">Rp. 65.000</td>
            <td>
            </td>
        </tr>';
    }




    echo $response;
    $i++;
}
?>

if you only use 2 else the script runs smoothly but if I add an error like the one above.

How i can resolve this error, is there code missing from my code above?

all help is greatly appreciated

</div>
  • 写回答

2条回答 默认 最新

  • dqc22586 2019-02-10 07:17
    关注

    You can not use multiple else my friend. You should use nested if else like:

    if ( checkdnsrr($domain, 'ANY')) {
    } else if ( checkdnsrr($domain, 'secondValue')) { // You are missing this part and not adding if condition
    } else if (checkdnsrr($domain, 'thirdValue')) { // You are missing this part and not adding if condition
    } else if (checkdnsrr($domain, 'fourthValue')) { // You are missing this part and not adding if condition
    } else {
    }
    

    You can check this on link: https://www.w3schools.com/php/showphp.asp?filename=demo_if_elseif

    Here you need to check your requirement and need to make your condition to show different price. I am not sure about your requirement, so I can not make particular condition for you. Hope it will help you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法