sh44n Posted June 11, 2008 Share Posted June 11, 2008 Sample Data -------------- "Costs of Goods & Services / Total Expenses","-88,105","-91,960","-46,339","-47,400","-48,692","-52,892","-41,672","-43,334","-46,671","-43,203" This is a CSV data including comma-separated numerics. The problem is when i try to split it with the following code, it also splits it on the basis of decimals, $arr_tag_pieces = explode(',',$value); I tried a trick by splitting it as follows i.e. splitting on the basis of [","] $arr_tag_pieces = explode('","',$value); but the problem is that the first element and last element of the array receives the double quotes in the beginning and the end respectively. $arr_tag_pieces[0] = "Costs of Goods & Services / Total Expenses $arr_tag_pieces[10] = -43,203" any suggestions/way-outs? Link to comment https://forums.phpfreaks.com/topic/109693-solved-splitting-csv-data-which-inlcudes-comma-separated-numerical-values/ Share on other sites More sharing options...
lordfrikk Posted June 11, 2008 Share Posted June 11, 2008 All your data is stored in $r[1]. <?php $s = '"Costs of Goods & Services / Total Expenses","-88,105","-91,960","-46,339","-47,400","-48,692","-52,892","-41,672","-43,334","-46,671","-43,203"'; $p = '_"([^"]+?)"_i'; preg_match_all($p, $s, $r); var_dump($r[1]); ?> Link to comment https://forums.phpfreaks.com/topic/109693-solved-splitting-csv-data-which-inlcudes-comma-separated-numerical-values/#findComment-563055 Share on other sites More sharing options...
effigy Posted June 11, 2008 Share Posted June 11, 2008 There's fgetcsv and str_getcsv. Link to comment https://forums.phpfreaks.com/topic/109693-solved-splitting-csv-data-which-inlcudes-comma-separated-numerical-values/#findComment-563128 Share on other sites More sharing options...
sh44n Posted June 11, 2008 Author Share Posted June 11, 2008 Thumbs up lordfrikk . Thanks. Link to comment https://forums.phpfreaks.com/topic/109693-solved-splitting-csv-data-which-inlcudes-comma-separated-numerical-values/#findComment-563358 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.