nicolas
nicolas

Reputation: 75

How to combine 2 strings into 1 array?

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

Answers (3)

KTAnj
KTAnj

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

Hytool
Hytool

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

Dhinju Divakaran
Dhinju Divakaran

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

Related Questions