开发者

Which escaping to use to insert a regular expression into database and getting it back unaltered?

What is the best way to insert a regular expression into a database and read it, I tried some php functions like

  • htmlentities()
  • htmlspecialchars()
  • serialize()

But after I fetch the regular expression from MySQL I can't use开发者_如何学Go it, it doesn't work. I tried with a text file to save the regular expression and result was same.


if u want to insert some special character into mysql then htmlentities() is useful with falgs

ENT_COMPAT  Will convert double-quotes and leave single-quotes alone.
ENT_QUOTES  Will convert both double and single quotes.
ENT_NOQUOTES  Will leave both double and single quotes unconverted.
ENT_IGNORE  Silently discard invalid code 

htmlentities($str, ENT_QUOTES, "UTF-8");  

htmlspecialchar() only convert some special characters to HTML entities like

'&' (ampersand) becomes '&'
'"' (double quote) becomes '"' when ENT_NOQUOTES is not set.
''' (single quote) becomes ''' only when ENT_QUOTES is set.
'<' (less than) becomes '&lt;'
'>' (greater than) becomes '&gt;'

also read

html_entity_encode

html_entity_decode

htmlentities

htmlspecialchars

HAPPY TO HELP :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜