Web Development Knowledge Base
| |
Sections :
Vous aussi, aidez les autres développeurs, publiez vos bouts de codes utiles et vos liens préférés ... Publiez un article ! |
Olivier Ligny - - 09/04/2008 - vue 50 fois
str2hex() / hex2str() en PHP pour encoder/décoder du texte en hexadécimalVoici deux fonctions PHP pour encoder/décoder du texte en hexadécimal :
function str2hex($string) {
$hex = "";
for ($i = 0; $i < strlen($string); $i++) {
$hex .= (strlen(dechex(ord($string[$i]))) < 2) ?
"0" . dechex(ord($string[$i])) : dechex(ord($string[$i]));
}
return $hex;
}
function hex2str($hex) {
$str = '';
for($i=0;$i < strlen($hex);$i+=2) {
$str.=chr(hexdec(substr($hex,$i,2)));
}
return $str;
}
|