-2

異なるリンクと URL を持つ 1 つの 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 に答える