Can someone tell me what command I use to translate ASCII values into decimal values. So it would translate p into 112 and so forth. Thanks.
Mark
ascii to decimal
Moderator: General Moderators
-
mccommunity
- Forum Commoner
- Posts: 62
- Joined: Mon Oct 07, 2002 8:55 am
This does not seem to be what I am looking for
This does not seem to work. It returns a 0 value every time I input a p and it should return 112
Works for me;
Result:
Code: Select all
<?php
$o[] = 'p';
$o[] = 'A';
$o[] = 'B';
foreach ($o as $val) {
echo ord($val) . '<br />';
}
?>Code: Select all
112
65
66Works for me too.... by pre-pending the &# to the decimal value you get the HTML entity for the character, so here is a little function which demonstrates the unpack() function in use for converting your email address to HTML entities....Although, obviously it will convert any string to it's equivalent HTML entities.
Does this qualify for the code snippet section?
Code: Select all
<?php
function email_obfuscate($address)
{
$ascii_dec = unpack ('C*', $address);
$n_chrs = count($ascii_dec);
$obfus = '';
$i = 0; while($i++ < $n_chrs) {
$obfus .= "&#{$ascii_dec[$i]};";
}
return $obfus;
}
echo email_obfuscate('somebody_somewhere@nobody-nowhere.com');
?>