ユーザーがドロップダウン メニュー (パスからすべてのファイルを一覧表示) から日付とオプションを選択して送信するフォームを作成しました。送信されると、ユーザーの入力は特定の形式で他のファイルに書き出されますが、フォームの下にも表示されるため、ユーザーは最終的な出力を確認できます。出力には、特に、選択したオプションに基づいたリンクが続く日付が含まれます (ユーザーは複数の選択を行うことができます)。
例:
option1.txt
ユーザーは、日付ピッカーとドロップダウンから08-01-2014 を選択します。file.js
これで、次の形式で に出力されました。
'08-01-2014' : '<a href="/path/option1.txt" target="_blank"><span>option1.txt</span></a>',
また、この形式でフォームの下に表示されています ( option1.txt はリンクであるため下線が引かれていますが、表示目的でここに下線を引くことができるかどうかはわかりません):
08-01-2014 : option1.txt
したがって、私の質問は、ユーザーの入力を書き留めるコードを変更して、それを示すコードがファイルを読み取ることができ、.xml08-01-2014 : option1
なしで表示できるようにする方法.txt
です。
ユーザーの入力を書き留める PHP コード ( writedown.php ):
<?php
$pickdate = $_POST['date'];
$workout = $_POST['workout'];
$date = ' \''.$pickdate .'\' : \'<a href="../routines/'.$workout.'" target="_blank"><span>'.$workout.'</span></a>\',' .PHP_EOL;
$file = 'test.js';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new workout to the file
$current .= $date;
$current = preg_replace('/};/', "", $current);
$current = $current.'};';
// Write the contents back to the file
file_put_contents($file, $current);
header( "location:index.php" );
?>
フォームの下にユーザーの入力を表示する PHP コード ( index.php ):
<?php
$file = "test.js";
$current = file_get_contents( $file );
$current = preg_replace('/var codropsEvents = {/', "", $current);
$current = preg_replace('/,/', "<br>", $current);
$current = preg_replace('/\'/', " ", $current);
$current = preg_replace('/ /', " ", $current);
$current = preg_replace('/};/', "", $current);
//$current = preg_replace('/option1.txt/', "<a href='test.php'>option1</a>", $current);
echo $current;
?>
私が知っていることはすべて試しましたが、インターネットで見つけることができました。最も近いのは、上記のコードのコメント行です。
//$current = preg_replace('/option1.txt/', "<a href='test.php'>option1</a>",
単一のエントリに対してのみ機能しており、同じ行を手動で追加して、別のエントリに適用できるようにする必要があります。
どんな助けでも大歓迎です。