Forum Moderators: coopster
function letters2numbers($s)
{
for($i=0;$i<strlen($s);$i++)
{
if ((96 < ord($s[$i])) && (ord($s[$i]) < 123))
{
$r .= ++$c;
}
else
{
$r .= $s[$i];
$c = 0;
}
}
return $r;
}
- note that this will increase the length of the string if you ever have a sequence of more than 9 characters. Your only alternative would be to wrap back to 0.
function convertLettersToNumbers($myString) {
for ($i = 0; $i < strlen($myString); $i++) {
$asciiValue = ord($myString{$i});
if ($asciiValue > 96 && $asciiValue < 123) {
$myString{$i} = $asciiValue - 96;
}
}
return $myString;
}
You might have to change a few things if your conversion isn't linear (a=1, b=2, etc.)
Hope that helps
[added: doh! I'm typing too slow!]
mavherick