Skip to content

Instantly share code, notes, and snippets.

@iluxonchik
Created April 24, 2014 15:07
Show Gist options
  • Save iluxonchik/11258147 to your computer and use it in GitHub Desktop.
Save iluxonchik/11258147 to your computer and use it in GitHub Desktop.
Convert text to ASCII (returns an integer).
function textToASCII($text){
/* recieves a chunk of text and returns the number resulting from converting all of the caharacters to ASCII */
$asciified = 0; // stores the "asciified" text
for ($i = 0; $i<strlen($text); $i++){
if (ord($text[$i]) < 10)
// if the character's ASCII code is less than 10, multiplay by 10, so that that integer can be "concatenated"
$asciified *= 10;
else if (ord($text[$i]) < 100)
// if the character's ASCII code is less than 100, multiplay by 100, so that that integer can be "concatenated"
$asciified *= 100;
else // if ord($text[i]) > 100
$asciified *= 1000;
$asciified += ord($text[$i]);
}
return $asciified;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment