Apa itu str_replace() ?
- Function str_replace() memiliki peran yang sama seperti ketika kita menggunakan fasilitas Replace All pada MS. Word.
- Function ini akan menggantikan suatu string dengan string yang lain.
Contoh-1:
$stringawal = "selamat datang di halaman web ATwiwit.Net";
$ubahstring = str_replace("web", "website", $stringawal);
echo "$ubahstring";
Contoh-2:
<?
$rawstring = "Welcome Muria kudus parent! <br>
Your offspring is a pleasure to have!
We believe pronoun is learning a lot.<br>
The faculty simple adores pronoun2 and you can often hear
them say \"Attah sex!\"<br>";
$placeholders = array('offspring', 'pronoun2', 'pronoun', 'sex');
$femalevals = array('daughter', 'her', 'she', 'girl');
$femalestr = str_replace($placeholders, $femalevals, $rawstring);
echo "Daughter: ". $femalestr;
?>
- Pada script di atas, array $placeholder berisi string-string dari $rawstring yang akan diganti.
- Berikut tampilan ketika dijalankan:
Daughter: Welcome Muria Kudus parent!
Your daughter is a pleasure to have! We believe she is learning a lot.
The faculty simple adores her and you can often hear them say "Attah
girl!"
Selanjutnya kita akan membahas tentang strtoupper() di PHP.
Your daughter is a pleasure to have! We believe she is learning a lot.
The faculty simple adores her and you can often hear them say "Attah
girl!"
Selanjutnya kita akan membahas tentang strtoupper() di PHP.
No comments:
Write komentar