1

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" }
2
  • what is expected output you want? Commented Jul 16, 2015 at 6:31
  • the output I want is: "storage-primary" Commented Jul 16, 2015 at 6:32

3 Answers 3

1

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);
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

Try this

 unset($array1[0]);
 $str = implode('-',$array1);
 echo $str;

OR

echo $array1[1]."-".$array1[2];

Output will be storage-primary

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.