Created
November 11, 2018 18:26
-
-
Save msisaifu/cbfe983b6f991d2182ba764d8b5c56f8 to your computer and use it in GitHub Desktop.
Counts all the character of a string ascending order
This file contains 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
<?php | |
$string = "hello!world!!! rrr"; | |
echo "<pre>"; | |
print_r(countChar($string)); | |
echo "</pre>"; | |
function countChar($string) | |
{ | |
$explodeString = str_split(strtolower($string)); | |
$countChar = array_count_values($explodeString); | |
ksort($countChar); | |
foreach ($countChar as $key => $value) | |
{ | |
$asciiVal=ord($key); | |
if ( | |
($asciiVal>=ord(' ') && $asciiVal<=ord('/')) || | |
($asciiVal>=ord(':') && $asciiVal<=ord('`')) || | |
($asciiVal>=ord('{') && $asciiVal<=ord('~'))) | |
{ | |
unset($countChar[$key]); | |
} | |
} | |
return $countChar; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment