Jump to content

getting an ascii value of a letter


Recommended Posts

hi i wrote a small encryption routine in visual basic and ported it to a few other programming languages but i really want to use it in php. However is there a function so i can get the ascii code for an individual letter and is there a way that i can pick each letter of a string individually for example

tree

will loop and get T

then will get ther ascii of t 45(this may not be the actually number just showing as example)

then after it does that it moves to the next letter which is r

then to e then to e after that
and so on and so on

any help would be great thanks
Link to comment
Share on other sites

Use the [a href=\"http://www.php.net/ord\" target=\"_blank\"]ord()[/a] function and a for loop:
[code]<?php
$str = 'This is a test string';
for($i=0;$i<strlen($str);$i++)
    echo $str{$i} . ' = ' . ord($str{$i}) . '<br>';
?>[/code]

Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.