duanlang1196 2012-06-10 22:24
浏览 26

PHP自定义错误问题

Currently, I have this code:

<?php
if (isset($_GET['s'])) {
    $itemid = $_GET['s'];
    $search = "$itemid";
    $query  = ucwords($search);
    echo "<title>Results for $query</title>";
    $string = file_get_contents('http://clubpenguincheatsnow.com/tools/newitemdatabase/items.php');
    if ($itemid == "") {
        echo "Please fill out the form.";
    } else {
        echo '<div id="content">';
        $string = explode('<br>', $string);
        foreach ($string as $row) {
            preg_match('/^(.+)\s=\s(\d+)\s=\s(\D+)\s=\s(\d+)/', trim($row), $matches);
            if (preg_match("/$query/i", "$matches[1]")) {
                echo "<a href='http://clubpenguincheatsnow.com/tools/newitemdatabase/info.php?id=$matches[2]'>";
                echo $matches[1];
                echo "</a><br>";
            }
        }
        echo '</div>';
    }
} else {
    echo "Item does not exist!";
}
?>

If "$matches[1]" has nothing in it, I want my code it to echo "Item does not exist!" How do I do this though? Please help!

I've tried something like if ($matches[1]=="") { echo "Item does not exist!"; } before, but it didn't work. This is what I got:

http://img685.imageshack.us/img685/998/28990b2c12d0423292d3574.png

See works fine right? Look what happens if $matches[1] DOES exist:

http://img528.imageshack.us/img528/3690/71472c9de6ec49118ee8d48.png

It still comes up! How can I make my code so it only echos the error if there is nothing for $matches[1]? PLEASE HELP ME!

If you are wondering, this is my code when I added the if ($matches[1]=="") { echo "Item does not exist!"; } in:

<?php
if (isset($_GET['s'])) {
    $itemid = $_GET['s'];
    $search = "$itemid";
    $query  = ucwords($search);
    echo "<title>Results for $query</title>";
    $string = file_get_contents('http://clubpenguincheatsnow.com/tools/newitemdatabase/items.php');
    if ($itemid == "") {
        echo "Please fill out the form.";
    } else {
        echo '<div id="content">';
        $string = explode('<br>', $string);
        foreach ($string as $row) {
            preg_match('/^(.+)\s=\s(\d+)\s=\s(\D+)\s=\s(\d+)/', trim($row), $matches);
            if (preg_match("/$query/i", "$matches[1]")) {
                echo "<a href='http://clubpenguincheatsnow.com/tools/newitemdatabase/info.php?id=$matches[2]'>";
                echo $matches[1];
                echo "</a><br>";
            }
        }
        echo '</div>';
        if ($matches[1] == "") {
        echo "Item does not exist!";
        }
    }
} else {
    echo "Item does not exist!";
}
?>

Any help to my question would be VERY HIGHLY APPRECIATED!

  • 写回答

2条回答 默认 最新

  • douaoren4402 2012-06-10 22:34
    关注

    Look at PHP's comparison operators

    if (empty($matches[1])) { echo "Item does not exist!"; }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?