All for Joomla All for Webmasters

Let's Play With Coding…

ASCII to HEX Convertion in PHP

Hi guys.. I was searching for function to convert ASCII to HEX in PHP accidentally there is no pre-build function so today I am going to share you a function which will do this conversation.

/**
 * CodeZone.in
 * Author: Dineshkumar
 * Contact : hi@codezone.in
 */
 function ascii2hex($ascii) {
  $hex = '';
  for ($i = 0; $i < strlen($ascii); $i++) {
    $byte = strtoupper(dechex(ord($ascii{$i})));
    $byte = str_repeat('0', 2 - strlen($byte)).$byte;
    $hex.=$byte." ";
  }
  return $hex;
}

Happy coding….

Related posts

Rotate Text using CSS

While developing web pages we some time require to rotate text of images present...

Leave a Comment

Leave a Reply