Forum Moderators: coopster
Say I have a paragraph with the following sentence:
You need to replace the carburetor, transmission, spark plugs, both driver and passenger mirrors, and tailights. This should come out to around $800.
I want to be able to pull out all the comma separated words/phrases and then re-order them and put them back into the paragraph..
So I would end up with something like:
You need to replace the both driver and passenger mirrors, transmission, spark plugs, and tailights, carburetor. This should come out to around $800.
Any ideas?
[opener][list of items].[result or outcome].
Then you could perform the following (not tested so might need tinkering):
$str = 'You need to replace the carburetor, transmission, spark plugs, both driver and passenger mirrors, and tailights. This should come out to around $800.;
//seperate sentences
$sentences = explode('.', $str);
//seperate items
$items = explode(',', $sentences[0]);
//You now have: $len = count($items) - 1; for($i = 1; $i <= $len; $i++) { elseif($i == $len) { $string = $string.'.'.$sentences[1]; [1][edited by: darrenG at 10:45 am (utc) on July 1, 2007]
//items[0] = 'You need to replace the carburetor';
//items= ' transmission';
//...and so on
$items[0] = substr($items[0], 0, strpos('the') + 4);
$items[] = substr($items[0], strpos('the') + 3);
$items[] = substr($items[$len], strpos('and') + 3);
$string = $items[0];
$items[0] = '';
shuffle($items);
if($i == $len - 1) {
$string .= $items[$i];
}
$string .= ' and'.$items[$i];
}
else
$string .= $items[$i].',';
}