Php 函数egeri()不';行不通

Php 函数egeri()不';行不通,php,function,eregi,Php,Function,Eregi,我有这段代码,但当我登录habbo时,该功能不适用于联机图像,它只是脱机显示图像: <?php $name = $_GET['habbo']; $home = file_get_contents("http://www.habbo.com.br/home/".$name); if (eregi("http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/

我有这段代码,但当我登录habbo时,该功能不适用于联机图像,它只是脱机显示图像:

<?php
$name = $_GET['habbo'];
$home = file_get_contents("http://www.habbo.com.br/home/".$name);
if (eregi("http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_online_anim.gif", $home))
{
$img = "http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_online.gif";
}
else
{
$img = "http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_offline.gif";
}
header("Content-type: image/gif");
$im = imagecreatefromgif($img);
imagegif($im);
imagedestroy($im);
?>

问题在于,在PHP5.5中完全删除了对5.4的修改。但也就是说,看看你的代码,你就不明白为什么要从
eregi
开始。请看这一行:

if (eregi("http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_online_anim.gif", $home))
正在发生的模式匹配到底是什么?对我来说,这似乎是一个简单的检查。所以我建议试试这个。为了便于阅读,我也在清理您的格式:

$name = $_GET['habbo'];

$home = file_get_contents("http://www.habbo.com.br/home/".$name);

$check = "http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_online_anim.gif";

if ($check == $home) {
  $img = "http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_online.gif";
}
else {
  $img = "http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_offline.gif";
}

header("Content-type: image/gif");

$im = imagecreatefromgif($img);

imagegif($im);
imagedestroy($im);
有几件事:

首先,不推荐使用不区分大小写的正则表达式标记(i)。因此,在需要进行正则表达式匹配的情况下,您应该切换到使用preg_匹配

其次,eregi和preg_匹配不返回布尔值。因此,您需要使用identity操作符(==或!==)来测试匹配项

最后,由于您在搜索中没有使用正则表达式,所以匹配的可能性很小。你需要这样做:

if (eregi('/someregex/i', $home) !== FALSE){
查看可以找到的PCRE样式正则表达式的语法,以及检查正在使用的函数的返回值,可能会对您有所帮助。在php.net上有一个关于使用identity操作符检查返回的注释

看起来您只是在搜索用户名,在这种情况下,通过搜索可能更有意义,因为它比正则表达式快得多,并且只搜索字符串文字,就像您现在所做的那样:

$name = $_GET['habbo'];
$home = file_get_contents("http://www.habbo.com.br/home/" . $name);
if (stripos($home, "<whatever you're searching for>") !== FALSE) {
试试这个:

<?php
$name = $_GET['habbo'];
$home = file_get_contents('http://www.habbo.com.br/home/'.$habbo);
if (stristr($home, 'http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_online_anim.gif') == TRUE)
{
    $img = 'http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_online.gif';
}
    else
{
    $img = 'http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_offline.gif';
}
header('Content-type: image/gif');
$im = imagecreatefromgif($img);
imagegif($im);
imagedestroy($im);

eregi()
已弃用,可能已从您使用的PHP版本中删除。您需要改为使用
preg_match()
(尽管我怀疑根本不需要正则表达式,标准的比较运算符也可以)。是的,看起来您可以使用“==”…警告:从PHP 5.3.0开始,此函数已被弃用。依赖这个功能是非常不鼓励的。我用谁的家伙??谢谢你的帮助,我是个笨蛋。抱歉:(像ereg、eregi、split等函数从PHP5.3开始就被弃用了(不仅弃用了,而且完全删除了)。阅读更多内容我现在测试了它,但还不能工作,我不明白,因为如果你只使用($check=$home),我会在线获取图像,但是如果我使用($check=$home)我离线获取图像,但我在线!$check=$home会将$check的值设置为$home的值,然后返回true。因此,它始终为true。$check==$home将查看$check是否与$home相同。请在php中签出。@user3133630问题的一部分是您的代码没有意义,并且使用
eregi
令人费解。所以现在你需要去掉
eregi
,但不清楚你的比较是什么,或者为什么会这样设置。意思是,
$home
中有什么内容,为什么要与这个巨大的URL进行比较?我试过了,但只是将图像脱机显示,而不是联机!!@user3133630我会重复我所说的,“因此,现在您需要删除eregi,但不清楚您的比较是什么,或者为什么设置为这样。也就是说,$home中有什么内容,以及为什么要与那个巨大的URL进行比较?”我也试过了,但不起作用,我在线但图像离线,可能是因为代码没有获取文件内容???测试它,首先检查代码是否获取“任何信息”,然后你可以一次消除一件事…刚刚在这里测试过,它正在工作,只需将“===TRUE”替换为“!==FALSE”…检查:我只需要一个代码,如果我在线,则显示在线图像,如果我离线,则显示离线图像。检查我发布的链接。我刚刚更改了真/假,并创建了一个$var以与STRISTR进行检查。
<?php
$name = $_GET['habbo'];
$home = file_get_contents('http://www.habbo.com.br/home/'.$habbo);
if (stristr($home, 'http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_online_anim.gif') == TRUE)
{
    $img = 'http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_online.gif';
}
    else
{
    $img = 'http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_offline.gif';
}
header('Content-type: image/gif');
$im = imagecreatefromgif($img);
imagegif($im);
imagedestroy($im);