将文本区域的内容保存到文本文件中php

问题描述:

我想在单击保存按钮后将文本区域的内容保存到我的计算机中的文本文件。我的代码有效,但HTML代码也包含在文本文件中。将文本区域的内容保存到文本文件中php

这里是我的代码:从textarea的内容的

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'] = ""; 
} 

实例保存:

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代码?

change echo $text to die($text);

+0

非常感谢你!有效! – anyadit