PHP函数无法附加结果

时间:2010-10-12 08:13:06

标签: php function

这是我的功能 http://www.ideone.com/slpPe

如果我不使用功能

    preg_match_all("{http://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}[^\s\"\\\'\<&]*}ix", $html, $marches);
    $download = $marches[0];
//var_dump();
    $i = 0;
    for ($i; $i <= count($download); $i++) {
        echo  "download|";
        $links = $download[$i];
        if (!eregi("avaxhome.ws|pixhost.info", $links)) {
            echo  $links . "<br/>";
        }
    }

并返回一些链接

download|

http://www.filesonic.com/file/24394419/1851684883.rar

http://depositfiles.com/files/g6wawevha

请帮我修理

2 个答案:

答案 0 :(得分:2)

两个问题:

for ($i; $i <= count($download); $i++) {

 // You are re-initializing $return in the loop..overwriting it.
  $return = "download|";  

只需在循环外移动启动:

$return = "download|";
for ($i; $i <= count($download); $i++) {

此外,您不应在{<1}}中使用

<=

它应该只是for ($i; $i <=count($download) 。这是因为在大小为<的数组中,N不是有效索引。有效索引为N0

N-1起,ereg函数系列也已弃用,因此最好停止使用它们。您可以改为使用5.3.0

preg_match

可以使用if (!eregi("avaxhome.ws|pixhost.info", $links)) 编写为:

preg_match

另请注意,正则表达式中的if (!preg_match("/avaxhome\.ws|pixhost\.info/i", $links)) 需要进行转义才能将其视为文字句点。

Working link

答案 1 :(得分:0)

尝试使用php的preg_match()代替ereg()

http://www.php.net/manual/en/function.preg-match.php