You are here

public static function ConversionHelper::asc2hex32 in Lightweight Directory Access Protocol (LDAP) 8.3

Converts all ASCII chars < 32 to "\HEX".

Parameters

string $string: String to convert.

Return value

string Converted string.

2 calls to ConversionHelper::asc2hex32()
ConversionHelper::escapeDnValue in ldap_servers/src/Helper/ConversionHelper.php
Escapes a DN value according to RFC 2253.
ConversionHelper::escapeFilterValue in ldap_servers/src/Helper/ConversionHelper.php
Escapes the given values so that they can be safely used in LDAP filters.

File

ldap_servers/src/Helper/ConversionHelper.php, line 246

Class

ConversionHelper
Conversion helper to escape values correctly for LDAP filters.

Namespace

Drupal\ldap_servers\Helper

Code

public static function asc2hex32($string) {
  for ($i = 0; $i < strlen($string); $i++) {
    $char = substr($string, $i, 1);
    if (ord($char) < 32) {
      $hex = dechex(ord($char));
      if (strlen($hex) == 1) {
        $hex = '0' . $hex;
      }
      $string = str_replace($char, '\\' . $hex, $string);
    }
  }
  return $string;
}