找不到变量web爬虫php

找不到变量web爬虫php,php,cloudflare,Php,Cloudflare,我正在用php开发一个网络爬虫,我总是遇到这个问题,但我没有找到解决它的方法 注意:未定义的变量:第16行C:\xampp\htdocs\dousser\index.php中的网站爬网 这是我的第二篇文章,没有显示错误,但也没有显示任何内容 <?php $website_to_crawl= "http://php.net"; $all_links= array(); function get_links($url) { global $all_links; $contents=

我正在用php开发一个网络爬虫,我总是遇到这个问题,但我没有找到解决它的方法

注意:未定义的变量:第16行C:\xampp\htdocs\dousser\index.php中的网站爬网

这是我的第二篇文章,没有显示错误,但也没有显示任何内容

<?php 

$website_to_crawl= "http://php.net";
$all_links= array();


function get_links($url)

{
global $all_links;
$contents= @file_get_contents($url);
$regexp= "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
preg_match_all("/$regexp/siU", $contents, $matches);
$path_of_url= parse_url($url, PHP_URL_HOST);

if (strpos($url, "https://") == true)
{
$type= "https://";
}
else
{
$type= "http://";
}


$links_in_array= $matches[2];

foreach ($links_in_array as $link)

{

if (strpos($link, "#") !== false)
{
$link= substr($link,0, strpos($link, "#"));
}

if (substr($link, 0, 1) == ".")
{
$link= substr($link,1);
}

if (substr($link, 0, 7) == "http://") {
$link= $link;
}

else if (substr($link, 0, 8) == "https://") {
$link= $link;
}

else if (substr($link, 0, 2) == "//") {
$link= substr($link,2);
}



else if (substr($link, 0, 1) == "#") {
$link= $url;
}
else if (substr($link, 0, 7) == "mailto:") {
$link= "[" . $link . "]";
}
else if (substr($link, 0, 1) != "/") {
    $link= "$type" .$path_of_url. "/" . $link;
}
else 
{
$link= "$type" .$path_of_url.$link;
}


if (!in_array($link,$all_links))
{
array_push($all_links, $link);
}



}//ends foreach 

}//ends function get_links

get_links($website_to_crawl);

foreach ($all_links as $currentlink)
{
get_links($currentlink);
}

foreach ($all_links as $currentlink)
{

get_links($currentlink);
}

foreach ($all_links as $currentlink)
{
if ((strpos($currentlink, "www.php.net") !== FALSE) && (strpos($currentlink, "http", 4) == FALSE))
{
echo $currentlink . "<br>";
$linkscount[] += $currentlink;
}
}

$count= count($linkscount);

echo "<br><br>There are $count links found by the crawler";

?>
此变量适用于$WEBITE_to_爬网要爬网的网站 我已经检查过它是http还是https网站 我已经测试过了

提前谢谢 在这种情况下,我正在使用网站url制作webcrawler,您可以使用:

if (strpos($url, "https://") == true)
而不是

if (strpos($website_to_crawl, "https://") == true)

它已经声明为@inzamaYou declare$website_to_craw=;上面是get_links函数及其在函数中的使用。您可以在get_links函数中声明它。或者使用if-strpos$url,https://==true而不是if-strpos$website\u-to\u-crawl,https://==trueThank@inzamadries,我已经做了第二篇文章。您可以看到,我已经做了第二次尝试,但没有任何更改,谢谢