My mission for this code is to generate a long strings with lots of words into tokens, and reformat each token as string array. The output is like this;
And this is the code segment.
<?php
//Tokenize to string array
$sampletext="abang
abu
ada
adat
adik
air
ajak
akal
akar
alah
alas
alim
aliran
alur
ambil
anak
angin
angkat
anjing
api
arang
asal
asam
atas
ayam
bahasa
baik
bangkai
banyak
bapa
basah
batu
bawa
bawah
bayang
bayar
bekas
belah
belahan
belakang
bendera
bengkak
beradu
berair
beralih
berani
berat
berbalik
berbantal
berbelah
berfikiran
bergendang
berhabis
beri
berita
berkandikan
berkerat
berlapang
berpatah
bersihkan
bertilam
bertongkat
berubah
besar
betul
biang
bidan
bintang
bongkar
bongkok
buah
bual
buang
buat
buaya
bujur
buka
buku
bulan
bulat
bunga
buruk
burung
busuk
busung
buta
cabut
cacing
cahaya
cakap
cakar
campur
cari
cecah
cepat
cerai
cerdik";
$wcount=0;
$wlist=array();
$tok = strtok($sampletext, " \n\t/?,.()@!|{}[]*\'\"<>");//regular expression of the delimiter
while ($tok != false) {//false means end of line
$wlist[$wcount]=$tok;
$tok = strtok(" \n\t/?,.()@!|{}[]*\'\"<>");
$wcount++;
}
//array with quotes
$string_array_list="candidate_list=array(\"";
for($i=0; $i<$wcount; $i++){//loop to perform double quote
$string_array_list=$string_array_list.trim($wlist[$i])."\",\"";
}
//end string_array_list
$string_array_list=$string_array_list.");";
echo $string_array_list;
?>
Comments
Post a Comment