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
https://forums.phpfreaks.com/topic/214988-splitting-string/
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
https://forums.phpfreaks.com/topic/214988-splitting-string/#findComment-1118390
Share on other sites

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.