Jump to content

Explode and Upload filetype select


Cyto

Recommended Posts

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

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
)

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 />';
}

?>

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.