[geeklog-devel] [geeklog-cvs] Geeklog-1.x/system/classes/authentication LDAP.auth.class.php, NONE, 1.1
Joe Mucchiello
joe at ThrowingDice.com
Thu May 1 15:47:34 EDT 2008
At 03:27 PM 5/1/2008, Dirk Haun wrote:
> function ascii2hex($ascii)
> {
> /* Adapted from function courtesy kuukelekuu at gmail dot com,
> * from http://www.thescripts.com/forum/thread519762.html
> */
> $hex = '';
>
> for ($i = 0; $i < strlen($ascii); $i++) {
> $byte = strtolower(dechex(ord($ascii{$i})));
> $byte = str_repeat('0', 2 - strlen($byte)) . $byte;
> $hex .= $byte;
> }
>
> return $hex;
> }
You should not use {$i} to subscript a string since according to the
PHP manual:
Note: <http://us.php.net/manual/en/language.types.string.php>Strings
may also be accessed using braces, as in $str{42}, for the same
purpose. However, this syntax is deprecated as of PHP 6. Use square
brackets instead.
Is there some reason this is not just a call to binhex()?
If there is, this saves a lot of calls to strlen/str_repeat and strtolower.
$hex = '';
$len = strlen($ascii);
for ($i = 0; $i < $len; ++$i) {
$hex .= str_pad(dechex(ord($ascii[$i])), '0', 2, STR_PAD_LEFT);
}
return strtolower($hex);
I realize this is adapted code. But during adaptation, one should cut
down on the cruft of older versions.
----
Joe Mucchiello
Throwing Dice Games
http://www.throwingdice.com
More information about the geeklog-devel
mailing list