Skip to content

Instantly share code, notes, and snippets.

@MrShennawy
Last active November 10, 2018 23:43
Show Gist options
  • Save MrShennawy/876dd52134d87a4790ffcfc7cb9edcd9 to your computer and use it in GitHub Desktop.
Save MrShennawy/876dd52134d87a4790ffcfc7cb9edcd9 to your computer and use it in GitHub Desktop.
get count of (nineteen) word in random string
<?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