tags:

views:

315

answers:

3

How is this function numtoalpha to print out the alphabetic equivalents of values that will be greater than 9 used? Results, something like this: 10 for A, 11 for B, etc....

PHP.net does not even have that function or i did not look in the correct place, but I am sure it said functions.

<?php
$number = $_REQUEST["number"];
/*Create a condition that is true here to get us started*/
if ($number <=9)
{
echo $number;
}
elseif ($number >9 && $number <=35) 
{
echo $number;
function numtoalpha($number)
{
echo $number;
}
echo"<br/>Print all the numbers from 10 to 35, with alphabetic equivalents:A for10,etc";
?>
+2  A: 

you need to use base_convert:

$number = $_REQUEST["number"];   # '10'
base_convert($number, 10, 36);   # 'a'
SilentGhost
Did not know about base_convert, thanks pretty cool function.
Newb
A: 

Try this:

<?php

  $number = $_REQUEST["number"];

  for ($i=0;$i<length($number);$i++) {
    echo ord($number[$i]);
  }

?>

This will give you the ascii code for the respective character. Diminish it by 55, and you get 10 for A, 11 for B etc ...

Martin Hohenberg
+2  A: 

You're essentially going to do some math to generate the correct ascii code for the value you want.

So:

if($num>9 && $num<=35) {
 echo(chr(55+$num))
}
dnagirl