Thursday, October 6, 2016

Reformatting string into tokens with quotes

Reformatting string into tokens with quotes


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;

image

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, " /?,.()@!|{}[]*"<

Go to link Download