Well, your problem is proper quoting. Your problem is that you need different quotes for MySQL and for HTML, and you can probably also set magic_quotes_gpc! When quoting, you always quote text for a specific output file , for example:
- string value for mysql query
like
expression for mysql query- html code
- Json
- mysql regex
- php regex
For each case, you need a different quote, because each use is present in a different syntax context. This also implies that quoting should not be done at the input to PHP, but at a specific output ! For this reason, functions like magic_quotes_gpc
are broken ( make sure they are turned off !!! ).
So, what methods can be used for citation in these specific cases? (Feel free to correct me, there may be more modern methods, but they work for me)
mysql_real_escape_string($str)
mysql_real_escape_string(addcslashes($str, "%_"))
htmlspecialchars($str)
json_encode()
- only for utf8! I use my function for iso-8859-2mysql_real_escape_string(addcslashes($str, '^.[]$()|*+?{}'))
- you cannot use preg_quote in this case, because the backslash will be reset twice!preg_quote()
EDIT: Regarding your original question - if you correct your quotation, you can, of course, use any characters in the lines, including single and double quotes.
source share