When using forms to process information, I found that the processing of text fields is incorrect. Example: ---------------------------------------------------------------test.html htmlheadtitleTextAreaTesttitleheadbodybgcolor # fffffffor#hodpostactiontest. php text textarea
When using forms to process information, I found that the processing of text fields is incorrect. For example, in the following table:
---------------------------------------------------------------
Test.html
TextArea Test
Test. php
$ Fp = fopen ($ filename, "w ");
Fwrite ($ fp, $ content );
Fclose ($ fp );
Echo "OK ";
?>
------------------------------------------------------
The preceding example is used for testing. to complete the test, you can enter a file name and the content of the file. After confirmation, you can save the file on the server. The following describes the content of a two-file.
Test.html has a form with a text box and a text field. Text box is used to enter the file name to save, text field
Used to input the file content. The default file name is "test.txt", and the default file content is "aaa" \ "bbb \". The form action is "post" and the execution file is "test. php ".
Test. php is simple. Open the specified file, write the file content, close the file, and output "OK ".
Originally, I thought the file content should be "aaa" \ "bbb \", but the result is not like this, but \ "aaa \" \ "bbb \\\"! A backslash is added before each double quotation mark (") and backslash (\) (in fact, there are single quotation marks and null (nul. Why? As a result, I checked the PHP Chinese manual and found magic_quotes_gpc and magic_quotes_runtime descriptions in the PHP. ini configuration. I knew it was because PHP automatically handled it. In this way, magic_quotes_gpc and magic_quotes_runtime in the PHP. ini configuration
If it is set to off, the result is correct.
But what if I cannot change the server? So I checked the string operator processing function again and found that the stripslashes () function can complete this task. In this way, first change PHP. ini to the original format, and then modify test. php as follows:
--------------------------------------------------
$ Fp = fopen ($ filename, "w ");
$ Content = stripslashes ($ content );
Fwrite ($ fp, $ content );
Fclose ($ fp );
Echo "OK ";
?>
--------------------------------------------
Check the results again to fully meet my needs!
Note that if you want to modify the file content. For example, you can first read the file content and put it into a text domain. you can modify the content. If the file contains special symbols, such as "<", ">", "&", and so on, the direct display will be inconsistent with the actual content. It doesn't matter. PHP also provides the htmlspecialchars () function to convert special characters into the HTML string format, so that the display and processing are correct.
This is a problem I found when processing text fields. I hope it will help you!