Jump to content


Photo

getting an ascii value of a letter


  • Please log in to reply
2 replies to this topic

#1 predator12341

predator12341
  • Members
  • PipPipPip
  • Advanced Member
  • 87 posts
  • LocationCheshunt, Hertfordshire, England

Posted 03 May 2006 - 03:53 PM

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
[a href="http://www.sloganizer.net/en/" target="_blank"][/a]

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 03 May 2006 - 04:22 PM

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

Ken

#3 predator12341

predator12341
  • Members
  • PipPipPip
  • Advanced Member
  • 87 posts
  • LocationCheshunt, Hertfordshire, England

Posted 03 May 2006 - 04:35 PM

kool thanks man
[a href="http://www.sloganizer.net/en/" target="_blank"][/a]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users