: This article mainly introduces the usage analysis of addcslashes and stripcslashes functions in PHP. if you are interested in PHP tutorials, refer to it. This article analyzes the usage of addcslashes and stripcslashes functions in PHP. We will share this with you for your reference. The details are as follows:
When I write an English version of a website, I fill in the English document after writing it. I don't have any questions when I fill it out. However, when I fill in the specified content, I cannot fill it in, and no error is reported, I checked the database and found that this field uses the "TEXT" data type. I thought it was because the content was too long, so I changed the data type to "longtext ", however, the same problem still occurs during submission. Next, let's introduce the addcslashes function!
Later, I asked my colleagues to find out why the punctuation marks "'" are in English. After MySQL runs here, it automatically considers the statement to be over, so I cannot fill it out. Now that the problem is identified, you have to find the corresponding solution, that is, add the escape character "\" before "'" in the text content. in PHP, the addcslashes and stripcslashes functions that automatically add or remove escape characters to strings are provided. after the test is added, the problem is solved! It can be seen that I do not strictly prohibit writing programs on weekdays, and I will always ignore such details. If HACKER finds these problems and uses them one by one, the website will basically be OVER, so everyone must take the precaution, don't make the same mistake as me.
The following describes the usage of these two functions:
String addcslashes (string str, string charlist)
The first parameter 'str' is the original string to be lost.
The charlist parameter contains the characters "\" before the original string.
String stripcslashes (string str)
Remove "\" from the string.
In addition, the addslashes function can also be used for escape processing.
Example:
<?php$sql = "update book set bookname='let's go' where bookid=1"; echo $sql."
"; $new_sql = addcslashes($sql,"'"); echo $new_sql."
"; $new_sql_01 = stripcslashes($new_sql); echo $new_sql_01."
"; echo addslashes($sql);?>
The running result is as follows:
update book set bookname='let's go' where bookid=1update book set bookname=\'let\'s go\' where bookid=1update book set bookname='let's go' where bookid=1update book set bookname=\'let\'s go\' where bookid=1
I hope this article will help you with PHP programming.
The above introduces the usage analysis of addcslashes and stripcslashes functions in PHP, including some content, and hope to help those who are interested in PHP tutorials.