Jump to content

Reading After The 2nd Space


sharpkj

Recommended Posts

I have the following code..


[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] // Get the position of the first space
$firstSpacePosition = strpos($line, ' ');
// Update array for the file names (everything after the first space)
$this->fileArray[$i] = substr($line, $firstSpacePosition, strlen($line));
// Update array for the directory names (everything before the first space)
$this->directoryArray[$i] = substr($line,0,$firstSpacePosition);
// Increment the counter
$i++; [/quote]

This looks at a line, finds the first space, then just takes everything after the first space and makes it fileArray[$i]. Everything before the first space becomes directoryArray[$i]. I'd like to make it so that everything before the first space is still directoryArray[$i], but then the word after the 1st space becomes secondArray[$i] and everything after the SECOND space becomes fileArray[$i].

Example

/directory/directory secondword file that I want displayed

would be
directoryArray = /directory/directory
secondArray = secondword
fileArray = file that I want displayed


Thanks for the help!
Link to comment
Share on other sites

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.