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? Quote Link to comment 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]); ?> Quote Link to comment Share on other sites More sharing options...
effigy Posted June 11, 2008 Share Posted June 11, 2008 There's fgetcsv and str_getcsv. Quote Link to comment Share on other sites More sharing options...
sh44n Posted June 11, 2008 Author Share Posted June 11, 2008 Thumbs up lordfrikk . Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.