我有 excel xheet 中的 url 列表。我正在从 excel 表中读取所有 url,现有的 url 和不存在的 url 存储在 serapare 文本文件中。我的问题是如果 url 没有响应然后循环停止。我的目标是发送该网址并检查下一个网址。
require_once 'excel_reader2.php';
$data = new Spreadsheet_Excel_Reader("urls.xls");
$totalsheets=count($data->sheets);
for($i=0;$i<count($data->sheets);$i++) // Loop to get all sheets in a file.
{
if(count($data->sheets[$i][cells])>0) // checking sheet not empty
{
$totalrows=count($data->sheets[$i][cells]);
for($j=1;$j<=count($data->sheets[$i][cells]);$j++) // loop used to get each row of the sheet
{
$name=$data->sheets[$i][cells][$j][1];
$url=$data->sheets[$i][cells][$j][2];
$file_headers =get_headers($url);
if(strpos($file_headers[0],"200")==true || $file_headers[0]!= 'HTTP/1.1 404 Not Found')
{
$exists = 'yes';
$myfile = fopen("existurls.txt", "w") or die("Unable to open file!");
$text .= $j." ".$name." ".$url."\n";
fwrite($myfile, $text);
fclose($myfile);
echo "Url exists";
}
else
{
$exists = 'no';
$myfile = fopen("nonexisturls.txt", "w") or die("Unable to open file!");
$text .= $j." ".$name." ".$url."\n";
fwrite($myfile, $text);
fclose($myfile);
echo "Url Not exists";
}
}
}
}
代码工作正常。但是,如果任何 url 没有响应,则循环将停止并且不会转到下一个。请帮助我如何跳过没有响应的 url 并继续循环。