Kelvin Kelvin - 1 year ago 34
HTML Question

how to get the spesific word from different string in php

for getting spesific word that i will use it for search term.

if i have a random word like :

$str="297819 - 123C, WHITLEY ROAD";

that $str is got from adrress which is got from autocomplete jQuery, every address is defined into 2 part. first
are "code", and
is the "address".

i know hot to get the "code" with this following code :

$b = substr($str,0,strpos($str,"-")-1)

it will be return the "code" only.

guys can you help me how to get the address?

p.s every code and address will be disperated by


Code and address separate by - so you can split it Using explode() as

$str="297819 - 123C, WHITLEY ROAD";
$data=explode("-",trim($str));// split string with -
echo $code=trim($data[0]);// get code 
echo $address=trim($data[1]);// get address

And use trim() to remove unnecessary space