-2

我有这个脚本,它需要一个带有不同链接和 url 的 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);

?>
4

1 回答 1

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";
于 2012-11-27T11:33:01.533 回答