私はこのようになりますディレクトリ構造を持っている:読むのファイル構造が、特定のファイルのみ
/expandables
- folder
- folder
- folder
- folder
- BannerInfo.txt
- index.html
folder
のそれぞれがまったく同じstuctureを持っています。 1つのファイルはBannerInfo.txt
とindex.html
です。これらのフォルダが約250あります。
これらのフォルダをループして、index.html
個の各ファイルをアレイに格納したいとします。 index.html
ファイルの中には、単純なHTMLとJavascriptがあり、後で表示する文字列を読みたいものです。
個別のフォルダからindex.html
ファイルのみをフィルタリングする方法に苦労しています。
この目的は、index.htmlファイルをランダムに選択してその内容をテキストエリアに入れたいからです。私は返された配列に単純なarray_rand()
を実行し、文字列を吐き出すことができると思った。
アイデア?
EDIT:
私はこのような何かを思い付いた:
<?
$expandables = array();
$expandables = scandir("expandables/");
$count = 0;
foreach($expandables as $expandable) {
if ($expandable != "." && $expandable != "..") {
$expandableCode = "expandables/" . $expandable . "/index.html";
// get value of index.html for select list
$expandableValue = file_get_contents($expandableCode);
// echo out options
echo "<option value='$expandableValue'>$expandable</option>";
}
}
?>
しかし、これは厳密に正しく動作していません。選択ボックスから一度選択すると、テキストエリアにindex.htmlの内容を動的に入力する方法はありますか?
ファイルを開いてファイルを読み込んで操作する必要があります。 PHPドキュメントを見てください:http://www.php.net/manual/en/function.file.php – B4NZ41