Welcome Guest, Not a member yet? Register   Sign In
sanitize textarea input for database insertion - best practice
#3

You can try this one, there are others out there on the web.

PHP Code:
function cleanText(string $string) : string
{
 
   $search = [
 
       "\xC2\xAB"    // « (U+00AB) in UTF-8
 
       "\xC2\xBB"    // » (U+00BB) in UTF-8
 
       "\xE2\x80\x98"// ‘ (U+2018) in UTF-8
 
       "\xE2\x80\x99"// ’ (U+2019) in UTF-8
 
       "\xE2\x80\x9A"// ‚ (U+201A) in UTF-8
 
       "\xE2\x80\x9B"// ‛ (U+201B) in UTF-8
 
       "\xE2\x80\x9C"// “ (U+201C) in UTF-8
 
       "\xE2\x80\x9D"// ” (U+201D) in UTF-8
 
       "\xE2\x80\x9E"// „ (U+201E) in UTF-8
 
       "\xE2\x80\x9F"// ‟ (U+201F) in UTF-8
 
       "\xE2\x80\xB9"// ‹ (U+2039) in UTF-8
 
       "\xE2\x80\xBA"// › (U+203A) in UTF-8
 
       "\xE2\x80\x93"// – (U+2013) in UTF-8
 
       "\xE2\x80\x94"// — (U+2014) in UTF-8
 
       "\xE2\x80\xA6"// … (U+2026) in UTF-8
 
   ];

 
   $replacements = [
 
       "<<",
 
       ">>",
 
       "'",
 
       "'",
 
       "'",
 
       "'",
 
       '"',
 
       '"',
 
       '"',
 
       '"',
 
       "<",
 
       ">",
 
       "-",
 
       "-",
 
       "...",
 
   ];

 
   return str_replace($search$replacements$string);

What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: sanitize textarea input for database insertion - best practice - by InsiteFX - 06-26-2019, 03:06 PM



Theme © iAndrew 2016 - Forum software by © MyBB