Contoh Operasi String ucwords() di PHP

Apa itu ucwords() ?

Karakter huruf pertama dari suatu kata dalam string juga dapat diubah menjadi huruf kapital menggunakan function ucwords().

Contoh:

<?
$stringJudul= "a title that could use some hELP";

$ucstringJudul = ucwords($stringJudul);
echo "Judul Baru - $stringJudul<br>";
echo "Judul Lama - $ucstringJudul";
?>
  • Hasilnya adalah:
Judul Baru - a title that could use some hELP
Judul Lama - A Title That Could Use Some HELP
  • Untuk mengubah HELP menjadi Help (pada tampilan outputnya) dengan cara mengubahnya (“hELP”) ke huruf kecil semua terlebih dahulu (“help”), kemudian huruf pertama dari “help” diberikan perintah ucwords(). 
  • Perhatikan modifikasi script berikut ini:
<?
$stringJudul= "a title that could use some hELP";

$lowercasestringJudul = strtolower($stringJudul);
$ucstringJudul = ucwords($lowercasestringJudul);
echo "Judul Baru - $stringJudul <br />";
echo "Judul Lama - $ucstringJudul";
?>
Selanjutnya kita akan membahas tentang Operasi String explode().

No comments:
Write komentar