PHP Indonesia - Facebook | PHP Indonesia is a community for everyone that loves PHP. Our focus is in the PHP world but our topics encompass the entire LAMP stack. Topics include PHP coding, to memcached handling, db optimizations, server stack, web server tuning, code deploying, hosting options and much much more. Youtube Channel : http://www.youtube.com/user/OurPHPIndonesia Twitter : @php_indonesia NOTE: Rules for Wall posting: https://www.facebook.com/groups/35688476100/doc/10151597056316101/ Daftar Keanggotaan : http://www.facebook.com/groups/35688476100/doc/10150671770741101/ | |
a.txt: ---------------------------- 1 I am big 2 I... Oct 19th 2013, 07:03, by Bayang Hitam | a.txt: ---------------------------- 1 I am big 2 I am small 3 I am biggest ---------------------------
gimana yah mau check jika "big" wujud pada line 3?? iaitu "I am biggest" dan print line tsbut?
output: --------------------- "big" exists in " I am biggest" --------------------- |
| | pertama kita pecah2 isi a.txt dalam array.. pake explode lalu check masing2 array kl ketemu tampilkan tulisan kyk di atas |
| | jadi, gimana mau select last line? iaitu line 3? |
| | coba perhatikan penggunaan foreach... |
| | nga ada basa basi nya gan say hi gtu,
coba pake preg_replace
<?php $string = '1 I am big 2 I am small 3 I am biggest'; $patterns = array(); $patterns[0] = '/1 I am big/'; $patterns[1] = '/2 I am small/'; $patterns[2] = '/3 I am biggest/'; $replacements = array(); $replacements[2] = '"big" exists in " I am biggest"'; $replacements[1] = ''; $replacements[0] = ''; echo preg_replace($patterns, $replacements, $string); ?> | | |
|
Tidak ada komentar:
Posting Komentar