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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.