How accurate does the distance calculation need to be? What will be the expected MAXIMUM distance between locations? (HINT: If it's 200KM or less and if accuracy to 100 meters is good enough, the code is much simpler. Shorter distances give better accuracy.)
Best "trick" is to store the latitude and longitude (and some additional info to make calculations easier) for each searched-for location in your database.
Here's a demo I did nearly 10 years ago. It's written in ASP code (not PHP, but not hard to convert) and is for the USA, so distances are in miles.
Enter any USA 5-digit zip code (use mine: 98296) and see what it shows you.
Or try 20509 with a radius of 0.1 miles.