I have dirty data. Sometimes it contains characters like this. I use this data to make queries like
WHERE a.address IN (\'mydatahere\')
For
In PHP - I approach this by only allowing printable data. This really helps in cleaning the data for DB. It's pre-processing though and sometimes you don't have that luxury.
$str = preg_replace('/[[:^print:]]/', '', $str);