Last active
November 10, 2018 23:43
-
-
Save MrShennawy/876dd52134d87a4790ffcfc7cb9edcd9 to your computer and use it in GitHub Desktop.
get count of (nineteen) word in random string
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
<?php | |
$str = "nnteirnnyeutbneveectnifngninejtfeesexn"; | |
$strlen = strlen( $str ); | |
$nChar = 0; | |
$iChar = 0; | |
$eChar = 0; | |
$tChar = 0; | |
for( $i = 0; $i <= $strlen; $i++ ) { | |
$char = substr( $str, $i, 1 ); | |
if($char == 'n'){ | |
$nChar++; | |
}elseif($char == 'i'){ | |
$iChar++; | |
}elseif($char == 'e'){ | |
$eChar++; | |
}elseif($char == 't'){ | |
$tChar++; | |
} | |
} | |
if($nChar < $eChar){ | |
if(($iChar && $tChar) >= $nChar / 3){ | |
echo round($nChar / 3); | |
} | |
}else{ | |
if(($iChar && $tChar) >= $eChar / 3){ | |
echo round($eChar / 3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment