RieqyNS13 icon

string function

RieqyNS13 | PRO | 03/25/13 02:33:59 PM UTC | 0 ⭐ | 374 👁️ | Never ⏰ | []
PHP |

920 B

|

None

|

0 👍

/

0 👎

<?php
/*Author : RieqyNS13 
FB : fb.me/RieqyNS13    
*/
$str = "      Devilzc0de.org mahoers  asd   ";
function jum_kata($str){
    $data = null;
    $str_r = str_replace(" ", "", $str);
    $uniq = array_unique(str_split($str_r));
    foreach($uniq as $value){
        $data .= $value." ada ".substr_count($str, $value)." biji\n";
    }
    return $data;
}
function jum_spasi_dan_kalimat($str){
    $str2 = trim($str);
    $preg = preg_replace("/\s+/", " ", $str2);
    $exp = explode(" ", $preg);
    $data = "jumlah kata = ".count($exp)."\njumlah spasi = ".substr_count($str, " ")."\n";
    return $data;
}
function jum_huruf_perkata($str){
    $data =null;
    $str = trim($str);
    $preg = preg_replace("/\s+/", " ", $str);
    $exp = explode(" ", $preg);
    for($a=1; $a<=count($exp); $a++){
        $data  .= "Kata ke-".$a." = ".strlen($exp[$a-1])."\n";
    }
    return $data;
}
echo jum_kata($str);
echo jum_spasi_dan_kalimat($str);
echo jum_huruf_perkata($str);
?>

Comments