2011-10-06 7 views
0

저장 버튼을 클릭 한 후 텍스트 영역의 내용을 컴퓨터의 텍스트 파일에 저장하려고합니다. 내 코드는 작동하지만 HTML 코드도 텍스트 파일에 포함되어 있습니다. 텍스트 영역에서 콘텐츠의텍스트 영역의 내용을 PHP의 텍스트 파일에 저장합니다.

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 코드를 제거 할 방법

?

답변

0

변경 echo $text부터 die($text);

+0

정말 고마워요! 그것은 일했다! – anyadit

관련 문제