views:

501

answers:

4

Can someone suggest a (preferably) graceful way to convert an ASCII character to its decimal equivalent using PHP?

+1  A: 

Try ord.

fbrereto
+1  A: 

ord() returns the integer ascii value of a character

chr() returns a character from an ascii value

dnagirl
+2  A: 

Hi. ord() is what you need

jkndrkn
+1  A: 
function ascii_to_dec($str)
{
  for ($i = 0, $j = strlen($str); $i < $j; $i++) {
    $dec_array[] = ord($str{$i});
  }
  return $dec_array;
}

example usage :

$ascii ="\t";
print_r( ascii_to_dec($ascii));

returns an array

Array
(
    [0] => 9
)
streetparade
Thanks for the help!
Jim Fell
you are welcome
streetparade