Menghitung jumlah karakter angka PHP
Anonymous
59 x views • 4 years ago
<?php
/*Memberi function*/
function hitung_vocal($kata){
$arr = str_split($kata);
$vocal = ['1', '2', '3', '4', '5','6','7','8','9'];
$found = array_intersect($vocal, $arr);
/*menghitung jumlah angka yang diinputkan*/
$count = array_count_values($arr);
$result = [];
foreach ($found as $item) {
$result[$item] = $count[$item];
}
return $result;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Hitung Karakter Angka</title>
</head>
<body>
<form method="POST" action="<?php $PHP_SELF ?>">
<!--membuat form input-->
<input type="number" name="kata" placeholder="input angka">
<!--tombol proses data -->
<button type="submit">Process</button>
</form>
<?php if ($_POST && isset($_POST['kata'])): ?>
<table border="0">
<!--Membuat file txt-->
<?php
$file ='file.txt';
$fp = fopen($file, 'w') or die ('Cannot file: '.$file);
if($fp)
?>
<?php
foreach (hitung_vocal($_POST['kata']) as $huruf => $jumlah): ?>
<tr>
<td><?php echo $huruf ?></td>
<td> : </td>
<td><?php echo $jumlah ?></td>
<!--Mengeluarkan hasil file txt-->
<?php
fwrite($fp, $huruf." = ".$jumlah."\r\n");
?>
</tr>
<?php
endforeach;
fclose($fp);
?>
</table>
<?php endif ?>
</body>
</html>
Berikut tampilan jika teman-teman berhasil Menghitung jumlah karakter angka PHP
AddThis Website Tools
You Might Also Like:
Next Post
Previous Post
Comment Policy: Silahkan tuliskan komentar Anda yang sesuai dengan topik postingan halaman ini. Komentar yang berisi tautan tidak akan ditampilkan sebelum disetujui.