如何用数字写字母

时间:2011-12-26 11:26:18

标签: php function

我想使用数字和数字(即w3b)将数字(即19455)更改为更短的内容,因此例如数字19455被w3b取代。当我输入w3b时,我希望能够取回那个号码。是否有我可以使用的现成功能,或者我必须自己构建它?

4 个答案:

答案 0 :(得分:4)

使用base_convert php函数:

示例:

$myNumInDecimal = "1234567787";
$myNumInBase36 = base_convert($myNumInDecimal, 10, 36);

这会给你:

kf12ln

http://php.net/manual/en/function.base-convert.php

但请注意,往返基地的时间应介于2..36之间。

答案 1 :(得分:0)

尝试将您的数字转换为十进制数到十六进制的函数,这将是一个很好的解决方案我想

答案 2 :(得分:0)

听起来像是在寻找str_replace

答案 3 :(得分:0)

我希望这会......

     <?
     # MAKE STRING INTO ARRAY TO FOR NUMBERS 0-9
   $numbers = array();
   for($counter =0; $counter <= 10; $counter++) {
       $numbers[$counter] = $counter;
    }


                 # FUNCTION TO CHANGE NUMBER INTO LETTERS
     function change_to_letters($string) {
    global $numbers;
  $replacements = array("a","b","c","d","e","f","g","h","i","j");
     $string = str_replace($numbers, $replacements, $string);
  return $string;
 }
     if(isset($_POST['submit'])){
    echo 'I changed '.$_POST['string'].' to this:<div style="border: 1px solid          #666;background-  color:                                                                #E6FAD9;width:200px;padding:5px;">'.change_to_letters($_POST['string']).'</div>';
          }

          ?>

   <!-- INPUT FORM --->
         <form action="" method="post">
           Enter some numbers here and i will change them into letters:<br /><input           name="string" type="text" size="15" maxlength="10"><br />
     <input type="submit" name="submit" value="Convert"><br />
     </form>