Inspekt\Inspekt::useFilterExt PHP Method

useFilterExt() public static method

We use this method of storing in a static class property so that we can access the value outside of class instances
public static useFilterExt ( boolean $state = null ) : boolean
$state boolean optional
return boolean
    public static function useFilterExt($state = null)
    {
        if (isset($state)) {
            Inspekt::$useFilterExtension = (bool) $state;
        }
        return Inspekt::$useFilterExtension;
    }

Usage Example

Beispiel #1
0
 /**
  * returns value with tags stripped and the chars '"&<> and all ascii chars under 32 encoded as html entities
  *
  * This will utilize the PHP Filter extension if available
  *
  * @param mixed $value
  * @return array|mixed|string @mixed
  * @tag filter
  */
 public static function noTagsOrSpecial($value)
 {
     if (Inspekt::isArrayOrArrayObject($value)) {
         return Inspekt::walkArray($value, 'noTagsOrSpecial');
     } else {
         if (Inspekt::useFilterExt()) {
             $newval = filter_var($value, FILTER_SANITIZE_STRING);
             $newval = filter_var($newval, FILTER_SANITIZE_SPECIAL_CHARS);
             return $newval;
         } else {
             $newval = strip_tags($value);
             // for sake of simplicity and safety we assume UTF-8
             $newval = htmlspecialchars($newval, ENT_QUOTES, 'UTF-8');
             /**
              * convert low ascii chars to entities
              */
             $newval = str_split($newval);
             for ($i = 0; $i < count($newval); $i++) {
                 $ascii_code = ord($newval[$i]);
                 if ($ascii_code < 32) {
                     $newval[$i] = "&#{$ascii_code};";
                 }
             }
             $newval = implode($newval);
             return $newval;
         }
     }
 }
All Usage Examples Of Inspekt\Inspekt::useFilterExt