7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
17 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
19 * @version $Id: Converter.php 16613 2009-07-10 06:55:41Z ralph $
23 * Zend_Ldap_Converter is a collection of useful LDAP related conversion functions.
27 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
28 * @license http://framework.zend.com/license/new-bsd New BSD License
30 class Zend_Ldap_Converter
33 * Converts all ASCII chars < 32 to "\HEX"
35 * @see Net_LDAP2_Util::asc2hex32() from Benedikt Hallinger <beni@php.net>
36 * @link http://pear.php.net/package/Net_LDAP2
37 * @author Benedikt Hallinger <beni@php.net>
39 * @param string $string String to convert
42 public static function ascToHex32($string)
44 for ($i = 0; $i<strlen($string); $i++
) {
45 $char = substr($string, $i, 1);
47 $hex = dechex(ord($char));
48 if (strlen($hex) == 1) $hex = '0' . $hex;
49 $string = str_replace($char, '\\' . $hex, $string);
56 * Converts all Hex expressions ("\HEX") to their original ASCII characters
58 * @see Net_LDAP2_Util::hex2asc() from Benedikt Hallinger <beni@php.net>,
59 * heavily based on work from DavidSmith@byu.net
60 * @link http://pear.php.net/package/Net_LDAP2
61 * @author Benedikt Hallinger <beni@php.net>, heavily based on work from DavidSmith@byu.net
63 * @param string $string String to convert
66 public static function hex32ToAsc($string)
68 $string = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $string);