2012-11-27 88 views
-2

我有這個腳本,它需要一個帶有不同鏈接和url的txt文件。並且此腳本檢查在.txt文件中的鏈接上存在的反向鏈接。我的腳本是這樣的我的腳本只讀第一個.txt文件,它首先被它讀取

<?php 
$needle = $_GET['utext']; 
$file = $_GET['ufile']; 
$source = file_get_contents($file); 
$new = explode("\n",$source); 
foreach ($new as $check){ 
    $a = file_get_contents(trim($check)); 
    if (strpos($a,$needle)){ 
     $found[] = $check; 
    } 
    else{ 
     $notfound[] = $check; 
    } 
} 

echo "Matches that were found: \n ".implode("\n","\n".$found)."\n"; 
echo "<br> <br> <br> <br>"; 
echo "Matches that were not found \n". implode("\n","\n".$notfound); 

?> 
+2

你怎麼可能相信在這個地方張貼包含「在這裏輸入代碼」的東西是可以接受的? :/請...看看編輯幫助。編輯框正上方有一個明亮的橙色按鈕。 – ThiefMaster

+1

你的問題是什麼? – GBD

+0

我與@GBD,實際的問題是缺少。也可以將各個部分包裝到它自己的函數中,這樣可以使您的代碼更加講話,並且可以更輕鬆地處理錯誤情況。 – hakre

回答

0

添加更多調試輸出。 printf/echo-debugging不是抽屜裏最尖銳的勺子,但它是你開始的。

<?php 
error_reporting(E_ALL); 
ini_set('display_errors', true); 

$needle = $_GET['utext']; 
$file = $_GET['ufile']; // that's ok regarding security? 
$new = file($file, FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); 
$new = array_map('trim', $new); 
echo '#entries: ', count($new), "\n"; 
$found = array(); $notfound=array(); 

foreach ($new as $check) { 
    echo 'processing: ', $check; 
    $a = file_get_contents($check); 
    echo ', length: ', strlen($a); 
    if (strpos($a,$needle)) { 
     echo ", found\n"; 
     $found[] = $check; 
    } 
    else { 
     echo ", not found\n"; 
     $notfound[] = $check; 
    } 
} 

echo '#Matches: ', count($found), "\n"; 
echo '#No-Matches: ', count($notfound), "\n"; 
echo "Matches that were found:\n ", implode("\n", $found), "\n"; 
echo "Matches that were not found:\n", implode("\n", $notfound), "\n"; 
+0

感謝VolkerK, 我只是想糾正我的劇本。你糾正了我。再次感謝。 – Honey

相關問題