Q: Extract city names from large text with php Hello i have an question here. Suppose that i have a long string which includes country names between other words.   
$str = "Department of Cardiology, West China Hospital, Sichuan University, No. 37 GuoXue Street, Boston,United states of america."

My goal is to extract all the country name of it. And I achieved it by following steps.
$str= str_replace(',', ' ', $str);
$var_array = preg_split('/(\|,|\.|-|\(|\)| )/', $str);
foreach($var_array as$data)
{
    echo $data;
    echo "<br/>";
}

Result
Department
of
Cardiology

West
China
Hospital
Sichuan
University

No

37
GuoXue
Street

Boston
United
states
of
america

But as you can see I cannot deal with country with multiple word names for eg "United states of america" as they are separated. Of course fix this issue manually is not an option as my real dataset is quite large.

A: You can try and traverse the string from opposite direction i.e in reverse order separating by comma. Because if you are using google location api then at last there will be always country name. 
So you can do something like this :- 
$address = array_reverse($str);
$address = explode(',', $address);  
