Q:

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 it, it doesn't work.
I tried with a text file to save the regular expression and result was same.

A:

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 '&amp;'
'"' (double quote) becomes '&quot;' when ENT_NOQUOTES is not set.
''' (single quote) becomes '&#039;' 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 :)

