<commit_before><?php
/**
 *
 * @package        100 Days of Code
 * @category       Source
 * @author         <NAME> <<EMAIL>> {@link http://michaelakanji.com}
 * @date           2017-10-09
 *
 */

function vowelsOccurrence( $phrase )
{
	preg_match_all( '/(a)?(e)?(i)?(o)?(u)?/i', $phrase, $matches );

	return
		count( array_filter( $matches[0], function ( $value ) {
			if ( $value ) return true;
		} ) );
}

function loopyVowelsOccurrence( $phrase )
{
	$vowelCount = 0;
	$vowels     = [ 'a', 'e', 'i', 'o', 'u' ];
	foreach ( str_split( $phrase ) as $char ) {
		if (in_array( $char, $vowels)) $vowelCount++;
	}
	return $vowelCount;
}

// get user input
$userWord         = ( @$_GET['testWord'] );
$vowelsOccurrence = vowelsOccurrence( $userWord );
?>

<!--// request user input-->
<form>
	<input name="testWord"
	       placeholder="Zoom"
	       value="<?= $userWord ?>">
	<input type="submit" value="Count Vowels">
</form>

<!--// Word Test result-->
<h5>
	<?= ( $vowelsOccurrence ) ? 'There are ' . $vowelsOccurrence . ' Vowels in "' . $userWord . '" </pre > ' : ''; ?>
</h5><commit_msg>Refactored Day 5 Task: Vowel Occurence<commit_after><?php
/**
 *
 * @package        100 Days of Code
 * @category       Source
 * @author         <NAME> <<EMAIL>> {@link http://michaelakanji.com}
 * @date           2017-10-09
 *
 */

function vowelsOccurrence( $phrase )
{
	preg_match_all( '/(a)?(e)?(i)?(o)?(u)?/i', $phrase, $matches );
	$vowelCount = [];
	$keys       = [ 'total', 'a', 'e', 'i', 'o', 'u' ];
	foreach ( $keys as $k => $v ) {
		$vowelCount[ $v ] = $v . " \t=> ". count( array_filter( $matches[ $k ], function ( $value ) {
			if ( $value ) return true;
		} ) );
	}

	return $vowelCount;
}

// get user input
$userWord         = ( @$_GET['testWord'] );
$vowelsOccurrence = vowelsOccurrence( $userWord );
?>

<!--// request user input-->
<form>
	<input name="testWord"
	       placeholder="Zoom"
	       value="<?= $userWord ?>">
	<input type="submit" value="Count Vowels">
</form>

<!--// Word Test result-->
<div>
	<?= ( $vowelsOccurrence ) ? 'There are <br> <pre>' . join( "\n", $vowelsOccurrence) . '</pre> Vowels in "' . $userWord . '" ' : ''; ?>
</div>
{'fraction_non_alphanumeric': 0.22515025427646787, 'fraction_numerical': 0.012482662968099861, 'mean_word_length': 2.956124314442413, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6983328', 'n_tokens_mistral': 866, 'n_tokens_neox': 832, 'n_words': 184}