Home  >  Article  >  Backend Development  >  php special character escape function

php special character escape function

WBOY
WBOYOriginal
2016-07-25 08:54:042671browse
This article introduces the usage of functions related to special character escaping in PHP, and masters the method of handling special characters in PHP. Friends in need can refer to it.

MySQL and PHP come with many functions that can handle character problems. Here are a few that are frequently used. ps: Since php6 does not support magic_quotes_gpc, the following things are assumed to be based on the condition of magic_quotes_gpc=off (I don’t know what new things will be released in php6...)

mysql_real_escape_string() Definition: Function to escape special characters in strings used in sql statements. Syntax: mysql_real_escape_string(string,connection) Description: This function escapes special characters in a string and takes into account the current character set of the connection, so it is safe to use with mysql_query(). Since the example code is too long, the function explanation link is given w3school phpnet

addslashes() Definition: The addslashes() function adds a backslash before the specified predefined characters. Syntax: addslashes(string) Note: By default, the php directive magic_quotes_gpc is on, automatically running addslashes() on all get, post and cookie data. Do not use addslashes() on strings that have been escaped by magic_quotes_gpc, as this will result in double escaping. When encountering this situation, you can use the function get_magic_quotes_gpc() to detect it. Since the example code is too long, the function explanation link is given w3school phpnet related functions stripslashes() removes backslash characters. (Used when explaining filter characters)

mb_convert_encoding() PHP internal code conversion function Version (php 4 >= 4.0.6, php 5) This function can convert various encodings to each other Related links phpnet

iconv() PHP internal code conversion function, same as above Because iconv() has a bug when converting gb2312, it needs to be handled like this PHP utility function for filtering special characters Special character filtering method for php form submission html special character filter php class How to escape special characters in url links Detailed explanation of php special character escaping php filter parameter special characters anti-injection php method to filter illegal and special strings php example: example of special character processing function



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP string sorting methodNext article:PHP string sorting method