Reputation: 14256
Can someone suggest a (preferably) graceful way to convert an ASCII character to its decimal equivalent using PHP?
Upvotes: 5
Views: 18412
Reputation: 193
Just to add onto streetparade's answer
foreach ($array as $decval)
{
echo $decval;
}
returns raw dec for the characters.
Upvotes: 0
Reputation: 32888
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
)
Upvotes: 12