Jump to content


This topic is now archived and is closed to further replies.


Reading After The 2nd Space

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


/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!

Share this post

Link to post
Share on other sites


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.