Your Ad Here

Posted By

misteroneill on 08/23/09


Tagged

array String magicquotes stripslashes


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

vali29
Dator
umang_nine


Stripslashes from String or Array


 / Published in: PHP
 

URL: http://www.misteroneill.com

If you're on a server that uses magic_quotes and you can't change that (depending on php.ini settings) I've used this function to remove annoying escape slashes. Also, sometimes you'll work with data coming from a database that someone wrote escaping slashes into.

  1. function stripslashes_deep($data) {
  2. return stripslashes($data);
  3.  
  4. if (is_array($data) && get_magic_quotes_gpc()) {
  5. foreach ($data as $i => $val) {
  6. $data[$i] = stripslashes($val);
  7. }
  8. }
  9. return $data;
  10. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: justin-china on August 24, 2009

function stripslashesdeep($data) { if (isstring($data) && getmagicquotes_gpc()) return stripslashes($data);

if (is_array($data) && get_magic_quotes_gpc()) {
    foreach ($data as $i => $val) {
        $data[$i] = stripslashes_deep($val);
    }
}
return $data;

}

You need to login to post a comment.