| |
|
|
| | Всем привет !
проблемма такаго рода : когда я пытаюсь получить все страницы с удаленного хоста , то выводится только первая ( цыкл прерывается ) Почему ?
где я ошибся ?
<?
set_time_limit(0);
$host = "www.mysyte.ru";
$path = "/video_list.php?vg=280&fp=0";
if ( !$buffer = getdata($host, $path) ) {
exit("Ошибка");
}
$pattern = "#<a[^>]*href=['\"]?([^\"'\s>]+)['\"]?[^>]*>#is";
preg_match_all($pattern, $buffer, $matches);// Получаем список всех ссылок
$str = $matches;
//----------------------------------------------------------
$i=0;
for($iu = 45; $iu < (count($str[1])-6); $iu++)//Отбрасываем ненужные ссылки
{
$i++;
$topic[$i]=$str[1][$iu];
}
//----------------------------------------------------------
foreach($topic as $index => $val)
{
$host = "www.mysite.ru";
$path = "/".$val;
if ( !$buffer = getdata($host, $path) ) {
exit("Ошибка"); }
print $buffer;
}
// функция получения страницы с удаленного хоста.
function getdata($host, $path)
{
$buffer = true;
$fp = @fsockopen("tcp://".$host, 80, $errno, $errstr, 10);
if (!$fp) {
return false;
} else {
$out = "GET $path HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Referer: $host$path\r\n";
$out .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n";
$out .= "Connection: Close\r\n";
$out .= "\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
$buffer .= fgets($fp, 1024);
}
fclose($fp);
}
return $buffer;
}
?>
|
| |
| |
|
|
| |
|
|
| |
для: dima2207
(04.01.2008 в 20:14)
| | | Выведите содержимое массива $topic - в нём больше одной ссылки?
<?php
echo "<pre>";
print_r($topic);
echo "</pre>";
?>
|
| |
| |
|
|