I found out when applying form processing information that the processing of text fields is not accurate. For example, in the following table: ---------------------------------------------------------------test.html htmlheadtitleTextAreaTest/title/headbodyb, I found out when applying form processing information, and the processing of text fields is inaccurate. For example, in the following table:
---------------------------------------------------------------
Test.html
TextArea Test
Test. php
$ Fp = fopen ($ filename, 'w ');
Fwrite ($ fp, $ content );
Fclose ($ fp );
Echo 'OK ';
?>
------------------------------------------------------
The above example is used for testing. it is important that you can input a file name and the content of the file. After confirmation, files can be retained on the server. The following briefly 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 input the file name to be retained, text field
Used to input the file content. The file name is set to 'test.txt ', and the file content is set to 'AAA' \ 'BBB \' by default \'. The form action is 'post' and the fulfillment file is 'test. php '.
Test. php is very simple. Open the specified file, write it into 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 (\) (there are actually 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 clarification in the PHP. ini configuration. I knew it was due to PHP's active processing. In this way, magic_quotes_gpc and magic_quotes_runtime in the PHP. ini configuration
If it is set to off, the results will be accurate.
But what if I cannot correct the server? So I checked the string character processing function again. I found the stripslashes () function to 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!
It should also be noted that, if you want to use the content of a modified file. For example, you can first read the file content and put it into the text field. If the file contains special symbols, such as '<', '>', '&', and so on, direct display will not match the actual content. It doesn't matter. PHP also provides the htmlspecialchars () function to convert special characters into the string structure of HTML, so that the display and processing are accurate.