Reputation: 75
my problem is I want to combine [1] with [2]. The source is "20100930-storage-primary.csv" but I only want "storage-primary". Can you help me?
This is the script I use to explode them:
$Name = 20100930-storage-primary.csv;
$array = explode( '.' , $Name);
$array1 = explode( '-' , $array[0]);
var_dump ($array1);
OUTPUT
array(3) { [0]=> string(8) "20100930" [1]=> string(7) "storage" [2]=> string(7) "primary" }
Upvotes: 1
Views: 60
Reputation: 1356
Try this
unset($array1[0]);
$str = implode('-',$array1);
echo $str;
OR
echo $array1[1]."-".$array1[2];
Output will be storage-primary
Upvotes: 0
Reputation: 1368
if your string pattern won't change then this should work,
substr($Name, strpos($Name,'-',1) + 1, strpos($Name,'.',1) - strpos($Name,'-',1) - 1)
Try it...
Upvotes: 0
Reputation: 903
Try unset
,implode
functions
$Name = $_FILES['filename']['name'];
$array = explode( '.' , $Name);
$array1 = explode( '-' , $array[0]);
unset($array1[0]);
$str = implode('-',$array1);
print_r($str);
var_dump ($array1);
Upvotes: 1