
Dari dulu kepengen banget kalo kode-kode yang ane tulis di blog ini bisa ada no urutnya :) .Sudah bermacam macam percobaan yang dilakukan tapi masih belum ada hasilnya :( .
Akhirnya
kemaren mumpung otak lagi fresh ,iseng iseng edit script dengan satu tujuan yang masih sama :) ,yaitu bagaimana cara membuat kode php/html nya mempunyai nomor urut sesuai jumlah baris kode nya -semangat-.
Hanya dengan menambahkan beberapa baris script ,ternyata apa yang selama ini ane idam-idamkan terwujud juga :tangisharu:
Begini nih caranya :),edit file
dbs-inc/dbs-functions.php ,lalu cari dan edit function
dy_highlight($text) .kode awalnya seperti ini
1 | function dy_highlight($text) |
2 | {$text=preg_replace('#<[^<>]*>#iU','<span style="color:# ff0000;">\\0</span>',$ text); |
3 | $text=preg_replace('#(<[^\s!]*\s)([^<>]*)([/?]?>)#iU',' \\1<span style="color:#008000;">\\2</span>\\3',$text); |
4 | $text=preg_replace('#<!--.*-->#iU','<span style="color:# 000000;">\\0</span>',$text); |
5 | $text=preg_replace('#("|&\#039;)[^<>]*("|&\#039;)# iU','<span style="color:#800000;">\\0</span>',$text); |
6 | $text=preg_replace('#\{(.*?)\}#is','<span style="color:#0000ff;">{\\1}</span>',$text); |
7 | return $text;} |
Hapus tulisan return $text; ,lalu tambahkan kode berikut :
1 | //Seandainya ada line (\r\n) yang banyak ,ubah jadi satu ajah :) |
2 | $text=preg_replace("#([\r\n ]+)#","\r\n",$text); |
3 | |
4 | //explode |
5 | $teks= explode("\r\n",$text); |
6 | |
7 | $tulisan=''; |
8 | |
9 | //jumlah baris |
10 | $jumlah=count($teks); |
11 | |
12 | //Looping |
13 | for($i=0; $i < $jumlah; $i++) |
14 | { //No urut |
15 | $no=$i+1; |
16 | |
17 | //Hasil |
18 | $tulisan.="<b>$no.</b> $teks[$i]\r\n";} |
19 | return $tulisan; |
Jadi kode lengkapnya seperti ini :
1 | function dy_highlight($text) |
2 | {$text=preg_replace('#<[^<>]*>#iU','<span style="color:# ff0000;">\\0</span>',$ text); |
3 | $text=preg_replace('#(<[^\s!]*\s)([^<>]*)([/?]?>)#iU',' \\1<span style="color:#008000;">\\2</span>\\3',$text); |
4 | $text=preg_replace('#<!--.*-->#iU','<span style="color:# 000000;">\\0</span>',$text); |
5 | $text=preg_replace('#("|&\#039;)[^<>]*("|&\#039;)# iU','<span style="color:#800000;">\\0</span>',$text); |
6 | $text=preg_replace('#\{(.*?)\}#is','<span style="color:#0000ff;">{\\1}</span>',$text); |
7 | $text=preg_replace("#([\r\n ]+)#","\r\n",$text); |
8 | $teks=explode("\r\n",$text); |
9 | $tulisan=''; |
10 | $jumlah=count($teks); |
11 | for($i=0; $i < $jumlah; $i++) |
12 | {$no=$i+1; |
13 | $tulisan.="<b>$no.</b> $teks[$i]\r\n";} |
14 | return $tulisan;} |
Buat yang mau ikutan pasang ,selamat mencoba :) ,hasilnya bisa dilihat di blog ini :)