Jump to content

Splitting String


ngreenwood6

Recommended Posts

I have a string like this:

 

Something,Somthing Else,"keyword1,keyword2,keyword3",Yet another

 

I need to split that string by the ,. However, I need the data that is n the quotes to remain as one even though it has commas because it is one item. I assume I need to use preg_split and have tried some code but none of it seems to work properly. If anyone has a better method or knows how I can split this up using preg_split the help is appreciated.

Link to comment
Share on other sites

There are some functions for handling csv strings.  If you are using php5.3+ you can use str_getcsv.  If not, look at the user notes for that entry, there is an entry that recreates that function for versions before php5.3.  Or if the text is coming from a file, read the file with fgetcsv instead of file_get_contents() or file() or fgets() or however else you are reading the file. 

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.