Jump to content

Selecting multiple parts of a split array?


idire

Recommended Posts

Right i had a string, which I split into multiple parts using:

 

$ex = explode(' ', $data);

 

which gives: $ex[0] $ex[1] $ex[2] ... $ex[n]

 

If i wanted to make a new string out of the parts from $ex[2] to $ex[n] how would i do that?

 

e.g. select all the data from a piece onwards.

 

Thanks

What version PHP?

 

When I try

$ex = explode('', $data);

 

I get

Warning: explode() [function.explode]: Empty delimiter. in C:\Inetpub\wwwroot\test\noname2.php on line 3

 

 

 

Can't you just

 

$str = 'abcdefg';
echo substr ($str, 2);        // cdefg

 

If you must use array

 

$str = 'abcdefg';
$ex = str_split($str);                      // put chars in array
echo join ('', array_splice($ex, 2));    // cdefg

it has to count the size each time through the loop and you get an unwanted space at the end.

 

OK, now I know it's a space

 

$str = 'a b c d e f g';
$ex = explode(' ', $str);
echo join (' ', array_splice($ex, 2));    // c d e f g

 

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.