2

单击“保存”按钮后,我想将文本区域的内容保存到计算机中的文本文件中。我的代码有效,但 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 代码?

4

1 回答 1

1

改为; echo $text_die($text)

于 2011-10-06T03:11:24.683 回答