2010-03-28 55 views
0

这里的URL是一个脚本进行任何错误错误检查和开放使用PHP

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

,这里是用外观相同的脚本来检查多个网址,并收到错误

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

    } 
    } 

的误差为警告:fopen()函数[function.fopen]:php_network_getaddresses:的getaddrinfo失败:没有主机是已知的。在G:/

究竟什么是错在这里?

+0

取决于 - 你检查什么网址?另外我注意到,你添加到http:而不是http:// - 是故意的,你存储//flibble.com而不是flibble.com? – Lee 2010-03-28 08:49:31

+0

这就是故意 任何网址,所有网址都有效,有些人在随机检查错误,没有错误但不 – X10nD 2010-03-28 08:51:24

回答

0

究竟是错在这里

  1. 什么获取未经许可的人的信息。如果网站愿意放弃网页,它将提供RSS。
  2. “检查” 所没有的领域。
+0

点@col sharpnel,我想知道是什么错误,谁愿意网站信息 – X10nD 2010-03-28 08:57:20

0

你尝试的fopen就在:

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

回声$t_u价值,并确保它是正确的。

+0

没有回音,显示它很好 – X10nD 2010-03-28 09:03:05

0

我有一个版本的脚本工作 - 这意味着,也许你的数据是错误的。在尝试获取URL的内容之前,您可以在域上进行DNS查找。从本质上说你错过了一些错误检查:

<?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]; 
     } 
    } 
} 
?> 
0

我会首先检查设置在该服务器上的php.ini文件allow_url_fopen选项。

+0

如果allow_url_fopen不允许,那么第一个脚本将不会运行。它是一个127.0.0.1服务器。 – X10nD 2010-03-28 11:17:08