2010-03-28 42 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