ngreenwood6 Posted October 2, 2010 Share Posted October 2, 2010 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 More sharing options...
.josh Posted October 2, 2010 Share Posted October 2, 2010 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 More sharing options...
litebearer Posted October 2, 2010 Share Posted October 2, 2010 will there be multiple occurrences of the quote encapsulated text within any one string? (ie... Something,Somthing Else,"keyword1,keyword2,keyword3",Yet another,"keyword4,keyword5,keyword6",Yet another) Link to comment https://forums.phpfreaks.com/topic/214988-splitting-string/#findComment-1118402 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.