You are here

function stripslashes_safe in Quiz 6.5

Same name and namespace in other branches
  1. 6.6 includes/moodle_support.php \stripslashes_safe()
1 call to stripslashes_safe()
s in includes/moodle_support.php

File

includes/moodle_support.php, line 267

Code

function stripslashes_safe($mixed) {

  // there is no need to remove slashes from int, float and bool types
  if (empty($mixed)) {

    //nothing to do...
  }
  else {
    if (is_string($mixed)) {

      //the rest, simple and double quotes and backslashes
      $mixed = str_replace("\\'", "'", $mixed);
      $mixed = str_replace('\\"', '"', $mixed);
      $mixed = str_replace('\\\\', '\\', $mixed);
    }
    else {
      if (is_array($mixed)) {
        foreach ($mixed as $key => $value) {
          $mixed[$key] = stripslashes_safe($value);
        }
      }
      else {
        if (is_object($mixed)) {
          $vars = get_object_vars($mixed);
          foreach ($vars as $key => $value) {
            $mixed->{$key} = stripslashes_safe($value);
          }
        }
      }
    }
  }
  return $mixed;
}