php - How To decode url_title() function in Codeigniter? -


i uri segment after use url_title() , pass url. try use rawurldecode() not perfect. example, have

$a = 'handhone -charger -handsfree -kabel data -buku panduan -kartu garansi '; 

and pass url url_title($a); , result ok

handhone0d0a-charger0d0a-handsfree0d0a-kabel-data0d0a-buku-panduan0d0a-kartu-garansi-platinum

i try use rawurldecode($this->uri->segment(10)) result :

handhone0d0a charger0d0a handsfree0d0a kabel data0d0a buku panduan0d0a kartu garansi platinum

i want :

handhone charger handsfree kabel dat buku panduan kartu garansi platinum

how that? whether there function available in codeigniter?

as want string different after encoding/decoding, i.e. without hyphens , newline characters, should first strip string those, before doing encoding. there 3 steps:

1. clean

with preg_replace can remove newlines , hyphens follows:

$a = preg_replace('/\s+\-/s', ' ', trim($a)); 

the value of $a clean:

handhone charger handsfree kabel data buku panduan kartu garansi

2. encode

instead of using url_title($a), use php native function urlencode pass $a on url:

urlencode($a) 

the value on url then:

handhone+charger+handsfree+kabel+data+buku+panduan+kartu+garansi

the + signs represent spaces, , convert third step:

3. decode

with procedure need use urldecode, not rawurldecode:

urldecode($this->uri->segment(10)) 

this gives:

handhone charger handsfree kabel data buku panduan kartu garansi


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -