Horde_Ldap_Util::escapeFilterValue PHP Метод

escapeFilterValue() публичный статический Метод

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.
public static escapeFilterValue ( array $values ) : array
$values array Values to escape.
Результат array Escaped values.
    public static function escapeFilterValue($values)
    {
        // Parameter validation.
        if (!is_array($values)) {
            $values = array($values);
        }
        foreach ($values as $key => $val) {
            // Escaping of filter meta characters.
            $val = str_replace(array('\\', '*', '(', ')'), array('\\5c', '\\2a', '\\28', '\\29'), $val);
            // ASCII < 32 escaping.
            $val = self::asc2hex32($val);
            if (null === $val) {
                // Apply escaped "null" if string is empty.
                $val = '\\0';
            }
            $values[$key] = $val;
        }
        return $values;
    }

Usage Example

Пример #1
0
 /**
  * Test escaping of filter values.
  */
 public function testEscapeFilterValue()
 {
     $expected = 't\\28e,s\\29t\\2av\\5cal\\1eue';
     $filterval = 't(e,s)t*v\\al' . chr(30) . 'ue';
     // String call
     $this->assertEquals(array($expected), Horde_Ldap_Util::escapeFilterValue($filterval));
     // Array call.
     $this->assertEquals(array($expected), Horde_Ldap_Util::escapeFilterValue(array($filterval)));
     // Multiple arrays.
     $this->assertEquals(array($expected, $expected, $expected), Horde_Ldap_Util::escapeFilterValue(array($filterval, $filterval, $filterval)));
 }
All Usage Examples Of Horde_Ldap_Util::escapeFilterValue