Jump to content

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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