DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

heinz has posted 2 posts at DZone. View Full User Profile

String2hex

04.04.2006
| 903 views |
  • submit to reddit
        // description of your code here

<?php
  function string2hex($string) 
  {
    $hex = NULL;
    for ($i=0; $i < strlen($string); $i++)
    {
      $ord = ord(substr($string,$i,1));
      if($ord < 16) {
    $hex.= '0'.dechex($ord);
      } else {
    $hex.= dechex($ord);
      }
      if ($i && ($i % 32) == 31) {
    $hex.= "\n";
      }
    }
    return $hex;
  }
?>