tags:

views:

33

answers:

4

Hello

Here is one script with out any errors

$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];

And here is the same script using a look to check multiple urls and getting errors

    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];

     }
  }

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

What exactly is wrong here?

A: 

What exactly is wrong here

  1. Getting someone's info without permission. If site willing to give a page away, it will provide an RSS.
  2. "Checking" unexistent domains.
Col. Shrapnel
Not the point @col sharpnel, I want to know what the error is, who wants site info
Jean
A: 

Just before you attempt a fopen:

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

Echo the value of $t_u and make sure it is correct.

codaddict
did the echo, displays it fine
Jean
A: 

I have a version of this script working - it implies that perhaps your data is wrong. You could do a DNS lookup on the domain before trying to get the contents of the URL. In essence you're missing some error checking:

<?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];
        }
    }
}
?>
Lee
A: 

I would first check the setting for allow_url_fopen in the php.ini file on this server.

Cups
if allow_url_fopen is not permitted then the first script would not run. Its a 127.0.0.1 server.
Jean