LdapTools\Utilities\LdapUtilities::encode PHP Метод

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

Encode a string for LDAP with a specific encoding type.
public static encode ( string $value, string $toEncoding ) : string
$value string The value to encode.
$toEncoding string The encoding type to use (ie. UTF-8)
Результат string The encoded value.
    public static function encode($value, $toEncoding)
    {
        // If the encoding is already UTF-8, and that's what was requested, then just send the value back.
        if ($toEncoding == 'UTF-8' && self::isBinary($value)) {
            return $value;
        }
        if (function_exists('mb_detect_encoding')) {
            $value = iconv(mb_detect_encoding($value, mb_detect_order(), true), $toEncoding, $value);
        } else {
            // How else to better handle if they don't have mb_* ? The below is definitely not an optimal solution.
            $value = utf8_encode($value);
        }
        return $value;
    }

Usage Example

Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function toLdap($password)
 {
     $this->validateConfiguration();
     if (!is_null($this->getLdapConnection())) {
         $password = LdapUtilities::encode($password, $this->getLdapConnection()->getConfig()->getEncoding());
     }
     return iconv("UTF-8", "UTF-16LE", '"' . $password . '"');
 }
All Usage Examples Of LdapTools\Utilities\LdapUtilities::encode