Hello all,

I'm new to the forum and had a question that I hope is a quick one. I'm looking for a way to convert a 17 digit account number into ascii format. The account number is in a mysql database.

I know I can use ord to get the ascii value of the left most character, but I'm looking for how I can take a variable and get the ascii value of the entire variable, not just the left most character.

For example:
<?php
$acct_no = ord('78945678123456785'); // this converts the first character to ascii, looking for a way to convert all the characters to ascii

print $acct_no; //this would print the entire account number in ascii format
?>

Basically, I need the account number in ascii format for a script i'm writing to save a file with the account number to be uploaded into software.

as always, thank you in advance!

    Simple stuff. Unsure why you would ask this stuff:

    $s = "78945678123456785";
    for ($i = 0; $i < strlen($s); $i++) $asc[]= ord($s[$i]);
    echo implode(",", $asc);

      Thank you Buzz!

      for some reason i couldn't figure out:
      $asc[]= ord($s[$i])

      Thank you!

        echo join(",", array_map("ord", str_split($s)));

          And of course, Weedpacket steps in and offers his genius one-liner. :p

          tceko1: Don't forget to mark this thread resolved (using the link under the Thread Tools menu) if it is.

            Write a Reply...