Hướng dẫn php escape special characters
(PHP 4, PHP 5, PHP 7, PHP 8) Nội dung chính addslashes — Quote string with slashes Descriptionaddslashes(string
A use case of addslashes() is escaping the aforementioned characters in a string that is to be evaluated by PHP:
The addslashes() is sometimes incorrectly used to try to prevent SQL Injection. Instead, database-specific escaping functions and/or prepared statements should be used. Parametersstring The string to be escaped. Return ValuesReturns the escaped string. ExamplesExample #1 An addslashes() example
See Also
roysimke at microsoftsfirstmailprovider dot com ¶ 12 years ago
hoskerr at nukote dot com ¶ 19 years ago
svenr at selfhtml dot org ¶ 11 years ago
= "He said \"Hello O'Reilly\" & disappeared.\nNext line..."; geekcom ¶ 3 years ago
hybrid at n0spam dot pearlmagik dot com ¶ 21 years ago
unsafed ¶ 17 years ago
divinity76 at gmail dot com ¶ 6 months ago
David Spector ¶ 8 years ago
stuart at horuskol dot co dot uk ¶ 13 years ago
Nate from RuggFamily.com ¶ 15 years ago
Adrian C ¶ 15 years ago
Picky ¶ 16 years ago
php at slamb dot org ¶ 19 years ago
luciano at vittoretti dot com dot br ¶ 16 years ago
Lars ¶ 10 years ago
joechrz at gmail dot com ¶ 16 years ago
array_keys($thearray) as $string) { DarkHunterj ¶ 13 years ago
baburaj dot ambalam at gmail dot com ¶ 2 years ago
= "5 + 3"; What is escaping special characters in PHP?Character Escaping Because PHP interprets and interpolates special characters inside double-quoted string literals and heredoc string literals, the backslash sign ( \ ) is used as an "escape character". For example, using \$name instead of $name prevents PHP from interpolating the $name variable. How do I allow special characters in PHP?Tip: To convert special HTML entities back to characters, use the htmlspecialchars_decode() function.. & (ampersand) becomes &. " (double quote) becomes ". ' (single quote) becomes '. < (less than) becomes <. > (greater than) becomes >. What is the use of Htmlspecialchars in PHP?The htmlspecialchars() function converts special characters into HTML entities. It is the in-built function of PHP, which converts all pre-defined characters to the HTML entities. What is the difference between Htmlentities and Htmlspecialchars in PHP?Difference between htmlentities() and htmlspecialchars() function: The only difference between these function is that htmlspecialchars() function convert the special characters to HTML entities whereas htmlentities() function convert all applicable characters to HTML entities. |