Wallpapers Forums Login

Convert Or Change Numbers Into Letter ASCII In PHP

ok, if you are here, its because you want to know how you can change numbers into letters.

for example, wouldn't it be cool if i had this number:

389 and convert it to something like this: xyz

i often use the base64_encode() function when i want to change numbers into letters

ok here we go. the first thing we are going to do is create an array to declare our number zero through nine, so i will use this code:

$numbers = array();
for($counter =0; $counter <= 10; $counter++) {
$numbers[$counter] = $counter;
}


now the second part will be to create a function so the function can search our string and change any numbers it finds within our string and change them into letters. so i would use this functions:

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;
}


ok, now that we have these, we can put our script all together, so lets do it and see how it works in actions.. the first you i want you to do is open your text editor. im using windows xp, so ill be using notepad for this turorials. so open a blank notepad and copy and paste this code into notepad:
numbers-into-letters.php:
<h1><a href="http://www.wallpaperama.com">WALLPAPERAMA.COM</a></h1>
<?
# THIS FILE WAS CREATED BY WALLPAPERAMA.COM - PLEASE DO NOT REMOVE THIS - THANK YOU

# MAKE STRING INTO ARRAY TO FOR NUMBERS 0-9
$numbers = array();
for($counter =0; $counter <= 10; $counter++) {
$numbers[$counter] = $counter;
}
# FUCNTION 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>';
}

?>
<p>Hello, Thanks for checking out this script create by Wallpaperama.com to show you how you can convert numbers into letters.</p>
<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>
<p align="center">Check out more scripts like this at <a href="http://www.wallpaperama.com">www.wallpaperama.com</a></p>
<p align="center">&lt;&lt; Go back to <a href="http://www.wallpaperama.com/forums/convert-or-change-numbers-into-letter-ascii-in-php-t306.html">Convert Or Change Numbers Into Letter</a></p>



2. now that you have copied and paste this code into notepad, save it as numbers-into-letters.php

3. upload numbers-into-letters.php to your PHP website and open it with your browser to see the script in action.

4. now if you dont have the patients to do it yourself, i put it all together so you can see it in action. Change Numbers Into Letters Tutorial

i would recommend that you tested on your site to make sure it works for you.

if you learned anything, i would appreciate your comments please.

thanks.

Matt Fri Aug 14, 2009
this is a *lot* easier:

$letters = 'abcdefghijklmnopqrstuvwxyz';
$letters[5]; // this outputs "f"
Carls Tue Apr 28, 2009
accepts numbers but then ... nothing.

links to your site, so it's working. but the command to display the conversion shows nothing.

firefox shows a script loading progress bar briefly in the status line.

tnx anyway.
redoso Tue Mar 31, 2009
i found this in redoso . com


convert or change numbers into letter ascii in php with binzhex() function

if you want to conver a number into letter or a string, then you've found the right article.

i wanted to do this for a project and it took me a while to find the answer. hopefully you can benefit from this:

first, copy and past the following code to a text editor like notepad.exe

<?php
$str = "hello world!";
echo binzhex($str) . "<br />";
echo pack("h*",binzhex($str)) . "<br />";
?>

save it and upload to your server, the call it with your browser, the following will be generated:

4y343c3c3fzxzz3fz world!
t.k. Wed Jan 07, 2009
how do you convert the following letter into number?

send = $?
+more = $?
____
money = $?
rinkesh Wed Nov 05, 2008
i want to convert y into one
z into two
3 into three
like wise all the number into words
how can i do this please help me for this.i want this in php
samsun01 Fri Oct 24, 2008
vvvvvvjhkj
knmn,n,mn,mn,mn,m
kool Tue Sep 23, 2008
0417072311122206182419181706180708 1222091824170711041707
ramnath Tue Aug 26, 2008
25=twenty five
Ramnath Tue Aug 26, 2008
25 = twenty five
KUL Tue Aug 12, 2008
change 0110 1101 and 0100 1101
test Mon Mar 31, 2008
it says you show how to convert a number into a letter/string, yet when i look through your code it only shows how to convert a word into a number....wrong way round.
ombres Mon Sep 10, 2007
dude you suuck..
php Thu Aug 24, 2006
If you want to conver a letters into numbers , i made this script that does the opposite of your script too.
I wanted to do this for a project and it took me a while to find the answer. Hopefully you can benefit from this:
The only requirement for this to work on your web pages is that you have PHP in your hosting. IF you don't have php, you can signup with www.webune.com for a php plan. if you have php, continue on...
First, copy and past the following code to a text editor like notepad.exe
CODE:
<HTML>
  <TITLE>Learn How to convert and change binary to hex in PHP Tutorial</TITLE>
  <HEAD>
  <style type="text/css">
  <!--
  .style2 {color: #0066FF}
  -->
  </style>
  </HEAD>
  <BODY>
  <h1 align="center">Learn How to convert and change binary to hex in PHP Tutorial</h1>
  <div align="center">Turotial by <a href="http://www.wallpaperama.com">Wallpaperama.com</a></div>
  <hr size="2" noshade>
  <?php
  if($_POST['word']){ ?>
  <h2 align="center">I changed <span  class="style2"><?php echo $_POST['word']; ?></span> into  <span  class="style2"><?php echo bin2hex($_POST['word']) ?></span></h2><?php } ?>
  <p><form name="form1" method="post" action="">
  <strong>Enter a word you wish to convert into numbers</strong>:
  <input name="word" type="text" value="wallpaperama">
  <input type="submit" name="Submit" value="Submit">
  </form>
  </p>
  <p>This Script was developed by <a href="http://www.wallpaperama.com">Wallpaperama.com</a> - Support us by telling your friends about wallpaperama and help contribut to the open source by adding your knowledge of PHP, Linux, Mysql and more to others, just like this script.</p>
  <p>Thank You</p>
  <p>Wallpaperama Team</p>
  <p><a href="http://www.wallpaperama.com/forums/show-display-relative-root-path-php-function-absolute-path-linux-hosting-t378.html"><< Go Back</a> </p>
  <p align="center">PHP Hosting by <a href="http://www.webune.com">Webune.com</a> </p>
  <p>
  </BODY>
  </HTML>

Save it and upload to your server, the call it with your browser.
Our friends at www.webune.com have provided us with PHP hosting to demostrate an example:
[url=http://www.wallpaperama.com/tutorials/letter-converter.php]CONVERT LETTERS INTO NUMBERS[/url]

Related Content

Information

Share

wallpaperama | Wallpapers | Forums | Terms Of Service

copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Mon May 06, 2013 (-8 GMT)
Powered by: Webune Forums V5