Hatalar kontrol ve PHP kullanarak bir URL açma

4 Cevap

Burada herhangi bir hata dışarı ile bir script

$url="http://yahoo.com";
$file1 = fopen($url, "r");
$content = file_get_contents($url); 


$t_beg = explode('<title>',$content);
$t_end = explode('</title>',$t_beg[1]);
echo $t_end[0];

Ve burada birden adresler kontrol etmek için bir göz kullanarak ve hataları alıyorsanız aynı script

    for ($j=1;$j<=$i;$j++) {
    if ($x[$j]!=''){

    $t_u = "http:".$x[$j];

    $file2 = fopen($t_u, "r");


        $content2 = file_get_contents($t_u); 
        $t_beg = explode('<title>',$content);
        $t_end = explode('</title>',$t_beg[1]);
                echo $t_end[0];

     }
  }

Hata Warning: fopen() [function.fopen]: php_network_getaddresses: getaddrinfo failed: No such host is known. in g:/

Tam olarak burada ne yanlış?

4 Cevap

Ne tam olarak yanlış olduğunu

  1. Izni olmadan bir kişinin bilgisi alınıyor. Uzakta bir sayfa için site istekli ise, bir RSS sağlayacaktır.
  2. Unexistent etki "kontrol etme".

Bir Fopen girişimi hemen önce:

$file2 = fopen($t_u, "r");

$t_u değeri yankı ve bunun doğru olduğundan emin olun.

Ben bu script çalışma bir sürümü var - bu belki de verilerin yanlış olduğunu ima eder. Sen URL içeriğini almaya çalışırken önce etki DNS araması yapabilir. Özünde bazı hata denetimi kaçırıyoruz:

<?php

$x = array('//yahoo.com', '//google.com', '//leenux.org.uk');
$i = 3;

for ($j=0;$j<$i;$j++) {
    if ($x[$j]!=''){
        $t_u = "http:".$x[$j];

        $content2 = file_get_contents($t_u); 

        if (preg_match("/\\<title\\>(.*)\\<\\/title\\>/", $content2, $matches)) {
            echo $matches[1];
        }
    }
}
?>

Bu sunucuda php.ini dosyasındaki allow_url_fopen için ilk ayarını kontrol ederim.