Jump to content

help with explode function


ltbaggz

Recommended Posts

i am trying to divide up a string using the explode function and i am having soem problems.  the string is created like so:

example2, 3:35&example1, 0:10&

what i want to get out of it is

array1[0] = example2
array1[1] = example1

array2[0] = 3:35
array2[1] = 0:10

the string can be any amount of elements long.
if any one has a quick answer i would appreciate it, im going to keep working on it now.

thanks
Drew
Link to comment
https://forums.phpfreaks.com/topic/34131-help-with-explode-function/
Share on other sites

Try this:

[code]
<?php
$str = "example2, 3:35&example1, 0:10";
$lines = explode("&",$str);
$array1 = array();
$array2 = array();
foreach($lines as $lines){
$parts = explode(",",$lines);
$array1[] = $parts[0];
$array2[] = trim($parts[1]);
}
print_r($array1);
print_r($array2);

?>
[/code]

Outputs this:

Array ( [0] => example2 [1] => example1 )
Array ( [0] => 3:35 [1] => 0:10 )

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.