Problem I found out that the text field was handled incorrectly when I used the form to process information. For example, one of the following tables:
---------------------------------------------------------------
Test.html
<title> TextArea Test </title>
<body bgcolor= "#FFFFFF" >
<form method= "POST" action= "test.php" >
FileName <input type= "text" name= "filename" value= "test.txt" ><br>
Content:<br>
<textarea name= "Content" cols= "rows=" > "AAA" \ "Bbb\" </textarea><br>
<input type= "Submit" name= "Submit" value= "written" >
<input type= "reset" name= "Submit2" value= "Rewrite" >
</form>
</body>
test.php
?
$fp=fopen ($filename, "w");
Fwrite ($fp, $content);
Fclose ($FP);
echo "OK";
?>
------------------------------------------------------
The above example is used to test, mainly to complete the user can enter a file name, and then can enter the contents of the file. After confirmation, you can save the file on the server. The following is a brief description of the contents of a two file.
There is a form in the test.html with a text box and a text field. The text box is used to enter the name of the file to save, the text field
Used to enter the contents of the file. The filename defaults to "test.txt" and the contents of the file are set to "AAA" \ "Bbb\" by default. The action of the form is "post" and the execution file is "test.php".
Test.php is very simple. Opens the specified file, writes the contents of the file, closes the file, and outputs "OK".
Originally I think the document content should be "AAA" \ "Bbb\", but the result is not so, but the "aaa\" \\\ "bbb\\\"! An escape backslash is added before each double quotation mark (") and backslash (\) (In fact, a single quotation mark and an empty (nul)). Why is that? So, I query the PHP Chinese manual, see the configuration of php.ini about MAGIC_QUOTES_GPC and magic_quotes_runtime instructions, I know is because of the automatic processing of PHP. In this way, I will php.ini the MAGIC_QUOTES_GPC and magic_quotes_runtime in the configuration
Set to OFF, the result is correct.
But what if I can't change the server? Then I looked at the string handler function, and I found that the stripslashes () function would do the job. This first change the php.ini to the original appearance, and then modify the test.php as follows:
--------------------------------------------------
?
$fp=fopen ($filename, "w");
$content=stripslashes ($content);
Fwrite ($fp, $content);
Fclose ($FP);
echo "OK";
?>
--------------------------------------------
Then check the results, fully meet my needs!
Also note that if you want to do an application that modifies the contents of the file. For example, first read the contents of the file, put into the text field, users can modify. Then when there are special symbols in the file, such as "<", ">", "&" and so on, the direct display will be inconsistent with the actual content. Never mind, PHP also provides the Htmlspecialchars () function to convert special characters into HTML string format, so that the display and processing are correct.
This is a problem I found when I was working on a text field and I hope it will help you!