@@ -93,10 +93,10 @@ |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
96 | - * example removeAccentsIstring( "Õ") output "O" |
|
97 | - * @param string $string |
|
98 | - * @return string |
|
99 | - */ |
|
96 | + * example removeAccentsIstring( "Õ") output "O" |
|
97 | + * @param string $string |
|
98 | + * @return string |
|
99 | + */ |
|
100 | 100 | public static function removeAccentsIstring($string) : string |
101 | 101 | { |
102 | 102 | return preg_replace(array("/(á|à|ã|â|ä)/", "/(Á|À|Ã|Â|Ä)/", "/(é|è|ê|ë)/", "/(É|È|Ê|Ë)/", "/(í|ì|î|ï)/", "/(Í|Ì|Î|Ï)/", "/(ó|ò|õ|ô|ö)/", "/(Ó|Ò|Õ|Ô|Ö)/", "/(ú|ù|û|ü)/", "/(Ú|Ù|Û|Ü)/", "/(ñ)/", "/(Ñ)/", "/(ç)/", "/(Ç)/"), explode(" ", "a A e E i I o O u U n N c C"), $string); |
@@ -73,17 +73,22 @@ |
||
73 | 73 | $characterDeficit = 0; //Gets incremented when an uppercase letter is encountered before $targetCharsPerWord characters have been collected since the last UC char. |
74 | 74 | $wordIndex = $targetWordLength; //HACK: keeps track of how many characters have been carried into the abbreviation since the last UC char |
75 | 75 | while ($stringIndex < strlen($strString)) { //Process the whole input string... |
76 | - if ($abbrevLength >= $targetLength) //...unless the abbreviation has hit the target length cap |
|
76 | + if ($abbrevLength >= $targetLength) { |
|
77 | + //...unless the abbreviation has hit the target length cap |
|
77 | 78 | break; |
79 | + } |
|
78 | 80 | $currentChar = $strString[$stringIndex++]; //Grab a character from the string, advance the string cursor |
79 | 81 | if (in_array($currentChar, $ucLetters)) { //If handling a UC char, consider it a new word |
80 | 82 | $characterDeficit += $targetWordLength - $wordIndex; //If UC chars are closer together than targetWordLength, keeps track of how many extra characters are required to fit the target length of the abbreviation |
81 | 83 | $wordIndex = 0; //Set the wordIndex to reflect a new word |
82 | 84 | } else if ($wordIndex >= $targetWordLength) { |
83 | - if ($characterDeficit == 0) //If the word is full and we're not short any characters, ignore the character |
|
85 | + if ($characterDeficit == 0) { |
|
86 | + //If the word is full and we're not short any characters, ignore the character |
|
84 | 87 | continue; |
85 | - else |
|
86 | - $characterDeficit--; //If we are short some characters, decrement the defecit and carry on with adding the character to the abbreviation |
|
88 | + } else { |
|
89 | + $characterDeficit--; |
|
90 | + } |
|
91 | + //If we are short some characters, decrement the defecit and carry on with adding the character to the abbreviation |
|
87 | 92 | } |
88 | 93 | $abbreviation .= $currentChar; //Add the character to the abbreviation |
89 | 94 | $abbrevLength++; //Increment abbreviation length |