[保存]ボタンをクリックした後、テキストエリアの内容をコンピューターのテキストファイルに保存したい。私のコードは機能しますが、HTMLコードもテキストファイルに含まれています。
これが私のコードです:
if(isset($_POST['submit_save'])) {
$file = "output.txt";
$output = $_POST['output_str'];
file_put_contents($file, $output);
$text = file_get_contents($file);
header("Content-type: application/text");
header("Content-Disposition: attachment; filename=\"$file\"");
echo $text;
} else {
$_POST['output_str'] = "";
}
保存するtextareaのコンテンツの例:
The quick brown fox jumps over the lazy dog.
[保存]ボタンをクリックすると、[名前を付けて保存]ダイアログボックスが表示され、output.txtとして保存されます。output.txtの内容は次のとおりです。
The quick brown fox jumps over the lazy dog.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Save Textarea Content</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>
.
.
. (all the way to </html>
</body>
</html>
保存したテキストファイルのHTMLコードを削除するにはどうすればよいですか?