note 23816 added to function.dechex
| From: | anon at anon dot co dot uk | Date: | Mon, 29 Jul 2002 14:47:28 +0000 |
| Subject: | note 23816 added to function.dechex | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-33872@lists.php.net to get a copy of this message | ||
I use the dechex function in a simple little encoder/decoder I use to let me convert binaries to
safe strings (for giving to programs outside PHP) but I mod the value against 16 to force a 2
character hex value return.
e.g. CRLF -> "%0d%0a"
function stringEncode($inString) { // Encodes string
return (string) preg_replace ("/([^a-zA-Z0-9])/e",
"'%'.dechex(ord(substr('$1', -1, 1))/16).dechex(ord(substr('$1',
-1, 1))%16)", $inString);
}
function stringDecode($inString) { // Decodes string
return (string) preg_replace ("/%([a-fA-F0-9][a-fA-F0-9])/e",
"chr(hexdec('$1'))", $inString);
}
--
http://www.php.net/manual/en/function.dechex.php
http://master.php.net/manage/user-notes.php?action=edit+23816
http://master.php.net/manage/user-notes.php?action=delete+23816
http://master.php.net/manage/user-notes.php?action=reject+23816