示例#1
0
 /**
  * Escapes the given VALUES according to RFC 2254 so that they can be safely used in LDAP filters.
  *
  * Any control characters with an ACII code < 32 as well as the characters with special meaning in
  * LDAP filters "*", "(", ")", and "\" (the backslash) are converted into the representation of a
  * backslash followed by two hex digits representing the hexadecimal value of the character.
  *
  * @static
  * @param array $values    Array of values to escape
  * @return array           Array $values, but escaped
  */
 function escape_filter_value($values = array())
 {
     // Parameter validation
     if (!is_array($values)) {
         $values = array($values);
     }
     foreach ($values as $key => $val) {
         // Escaping of filter meta characters
         $val = str_replace('\\', '\\5c', $val);
         $val = str_replace('*', '\\2a', $val);
         $val = str_replace('(', '\\28', $val);
         $val = str_replace(')', '\\29', $val);
         // ASCII < 32 escaping
         $val = Net_LDAP_Util::asc2hex32($val);
         if (null === $val) {
             $val = '\\0';
         }
         // apply escaped "null" if string is empty
         $values[$key] = $val;
     }
     return $values;
 }