私は便利な php スクリプトを使って作業してきました。このスクリプトはサイトをスキャンし、見つかったすべてのページへのリンクを吐き出します。問題は、すべての .inc.php ファイルを含む「includes」フォルダーもスキャンしていることです。
明らかに、サイトをスキャンするときにこのフォルダーを無視したいのですが、私の人生では、スクリプトを編集してそうするように指示する方法がわかりません.
スクリプトは次のとおりです。
<?php
// starting directory. Dot means current directory
$basedir = ".";
// function to count depth of directory
function getdepth($fn){
return (($p = strpos($fn, "/")) === false) ? 0 : (1 + getdepth(substr($fn, $p+1)));
}
// function to print a line of html for the indented hyperlink
function printlink($fn){
$indent = getdepth($fn); // get indent value
echo "<li class=\"$indent\"><a href=\"$fn\">"; //print url
$handle = fopen($fn, "r"); //open web page file
$filestr = fread($handle, 1024); //read top part of html
fclose($handle); //clos web page file
if (preg_match("/<title>.+<\/title>/i",$filestr,$title)) { //get page title
echo substr($title[0], 7, strpos($title[0], '/')-8); //print title
} else {
echo "No title";
}
echo "</a></li><br>\n"; //finish html
}
// main function that scans the directory tree for web pages
function listdir($basedir){
if ($handle = @opendir($basedir)) {
while (false !== ($fn = readdir($handle))){
if ($fn != '.' && $fn != '..'){ // ignore these
$dir = $basedir."/".$fn;
if (is_dir($dir)){
listdir($dir); // recursive call to this function
} else { //only consider .html etc. files
if (preg_match("/[^.\/].+\.(htm|html|php)$/",$dir,$fname)) {
printlink($fname[0]); //generate the html code
}
}
}
}
closedir($handle);
}
}
// function call
listdir($basedir); //this line starts the ball rolling
?>
これで、スクリプトが特定のファイルを無視するように指示されている場所を確認でき、追加しようとしました:
&& $dir != 'includes'
...多くの場所でそれを行っていますが、私のphpの知識は、そのコードをスクリプトに統合する方法を正確に知るにはあまりにも不安定です.
誰かが助けてくれるなら、あなたは私を非常に大きな頭痛の種から救ってくれるでしょう. 乾杯。