Jump to content

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

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.