Created
April 24, 2014 15:07
-
-
Save iluxonchik/11258147 to your computer and use it in GitHub Desktop.
Convert text to ASCII (returns an integer).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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