Cyto Posted June 24, 2012 Share Posted June 24, 2012 Hi, I'm exploding a list of result that are separated with comma, but I have also comma's in the value from the list. Is it possible to explode without removing the comma of the values? Example of list: 10,24,13,145 etc. Values are: 10,24 13,145 P.S I didn't wanted to open a new topic. Is it also possible when I browse a file to upload. I can select any file(All Files). Can it be done so I can choose only image file types? Cyto Link to comment https://forums.phpfreaks.com/topic/264697-explode-and-upload-filetype-select/ Share on other sites More sharing options...
Barand Posted June 24, 2012 Share Posted June 24, 2012 assuming they are always in pairs <?php $str = '10,24,13,145'; $a = explode(',', $str); $b = array_chunk($a, 2); // put into pairs $c = array(); foreach ($b as $pair) { $c[] = join(',', $pair); } ?> $c contains Array ( [0] => 10,24 [1] => 13,145 ) Link to comment https://forums.phpfreaks.com/topic/264697-explode-and-upload-filetype-select/#findComment-1356650 Share on other sites More sharing options...
Cyto Posted June 24, 2012 Author Share Posted June 24, 2012 Thx it works, but I'm using it in a for loop. How can I do this in a for loop? Link to comment https://forums.phpfreaks.com/topic/264697-explode-and-upload-filetype-select/#findComment-1356700 Share on other sites More sharing options...
Barand Posted June 24, 2012 Share Posted June 24, 2012 Don't know without seeing what you doing Link to comment https://forums.phpfreaks.com/topic/264697-explode-and-upload-filetype-select/#findComment-1356703 Share on other sites More sharing options...
Cyto Posted June 24, 2012 Author Share Posted June 24, 2012 My code: $a = explode(",", $str); $b= explode(",", $str2); for( $i = 0, $c = count($a); $i < $c; $i++ ) { echo $a[$i]."\n"; echo $b[$i]."\n"; } Link to comment https://forums.phpfreaks.com/topic/264697-explode-and-upload-filetype-select/#findComment-1356704 Share on other sites More sharing options...
Barand Posted June 25, 2012 Share Posted June 25, 2012 How are you creating those original strings in the first place? Is there the option of using a character other than comma to sidestep your problem? Link to comment https://forums.phpfreaks.com/topic/264697-explode-and-upload-filetype-select/#findComment-1356791 Share on other sites More sharing options...
Cyto Posted June 25, 2012 Author Share Posted June 25, 2012 I thought of that at the first place, but I didn't know how. The strings come from a ajax post in a array. I'm calling the array like: var numbers = []; The post contains like this: '10,24,13,145' etc. Link to comment https://forums.phpfreaks.com/topic/264697-explode-and-upload-filetype-select/#findComment-1356803 Share on other sites More sharing options...
Barand Posted June 25, 2012 Share Posted June 25, 2012 My code: $a = explode(",", $str); $b= explode(",", $str2); for( $i = 0, $c = count($a); $i < $c; $i++ ) { echo $a[$i]."\n"; echo $b[$i]."\n"; } What do $str and $str2 contain at this point? Link to comment https://forums.phpfreaks.com/topic/264697-explode-and-upload-filetype-select/#findComment-1356909 Share on other sites More sharing options...
Cyto Posted June 25, 2012 Author Share Posted June 25, 2012 $str = "00:01:54,938", "00:03:10,900", "00:03:14,826" $str2 = "00:01:57,974", "00:03:14,825", "00:03:17,851" I could only get this from firebug in a console.log, but these are the values that I get from ajax. Btw thx for helping me. Link to comment https://forums.phpfreaks.com/topic/264697-explode-and-upload-filetype-select/#findComment-1356931 Share on other sites More sharing options...
Barand Posted June 26, 2012 Share Posted June 26, 2012 Try using the ", " to split them <?php $str = trim($str,'"'); $a = explode('", "', $str); $str2 = trim($str2,'"'); $b = explode('", "', $str2); foreach ($a as $k=>$item) { echo $item . '<br />'; echo $b[$k] .'<br /><br />'; } ?> Link to comment https://forums.phpfreaks.com/topic/264697-explode-and-upload-filetype-select/#findComment-1357019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.