Jump to content

how break a string into sections


svgmx5

Recommended Posts

so i have this string that i want to search on the database

 

My database has 3 parts city, state, country

 

and i have a string that is say "new york city, ny, united states"

 

and i want to be able to be able to look into the database but search those three sections so for example

 

"New York City" i would like to search under city

"NY" i want it to search under state

and "United States" i want to search under country

 

so basically how can i split the string  into those three sections??

 

hope someone can help me with this

Link to comment
https://forums.phpfreaks.com/topic/227856-how-break-a-string-into-sections/
Share on other sites

You could use the expode() function to split the string into an array:

$string = explode(",", $yourstring);
$city = $string[0];
$state = $string[1];
$country = $string[2];

 

And then search for each one in the DB by using the $city, $state, $country variables.

 

This could be one way of doing it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.