Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = <<<END
- Alexandria
- Berowra Waters
- Campsie
- Doonside
- East Ryde
- Fairfield East
- Granville
- Heathcote
- Ingleburn
- Jannali
- Kirrawee
- Lane Cove North
- Maianbar
- Neutral Bay
- Old Toongabbie
- Parramatta
- Queenscliff
- Raby
- Sans Souci
- Tempe
- Ultimo
- Vaucluse
- Woolloomooloo
- Yagoona
- Zetland
- END;
- function remove_vowels($a){
- if(!in_array($a, array('A', 'E', 'I', 'O', 'U', ' '))){
- return $a;
- }
- }
- $input = explode("\n", $input);
- $unwanted = array('A', 'E', 'I', 'O', 'U', ' ');
- $max_len = null;
- foreach($input as $value){
- if(strlen($value) > $max_len){
- $max_len = strlen($value);
- }
- $subject = explode(" ", $value);
- $outword = null;
- foreach($subject as $value2){
- $word_array = null;
- $string_array = str_split($value2);
- $first_character = $string_array[0];
- if(!in_array($first_character, $unwanted)){
- $first_character = '';
- }
- //$last_two_vowels = str_replace("#([aeiou]{2}|*)#") that isn't going to work
- if(in_array(strtoupper($string_array[count($string_array)-2]), $unwanted) && in_array(strtoupper($string_array[count($string_array)-1]), $unwanted)){
- //this means that both of the characters are a vowel,
- // therefor they must not be removed, or more precisely, they will later be added to the end
- $end_vowels = $string_array[count($string_array)-2].$string_array[count($string_array)-1];
- }else{
- $end_vowels = '';
- }
- foreach($string_array as $char){
- if(!in_array(strtoupper($char), $unwanted)){
- $word_array[] = $char;
- }
- }
- $outword[] = $first_character.implode($word_array).$end_vowels;
- }
- $output[] = implode($outword);
- }
- foreach($input as $key => $value){
- echo str_pad($value, $max_len+1).$output[$key]."\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment