我有一個包含地址的字符串,我需要知道該地址正在使用哪種街道類型。下面是一個例子:在地址中獲取街道類型
$street = "100 road Overflow";
$streetTypes = array("ROAD", "ST", "ABBEY", "BLVD", "ALLEY", "CAR");
//find and save the street type in a variable
//Response
echo "We have found ".$streetType." in the string";
另外,地址是由用戶提交的,格式從不相同,這使事情變得複雜。到目前爲止,我已經看到這樣的格式:
100 ROAD OVERFLOW
100,road Overflow
100, Overflow road
解決此問題的最佳方法是什麼?
這裏是一個回答已發佈:http://stackoverflow.com/questions/13795789/check-if-string-contains-word-in-array。不完全是你需要的,但非常接近 –