Get a sentence from a string. [Fixed]
Posted: Wed Jun 01, 2005 7:36 pm
This is probably pretty simple for someone who can use regular expressions.
Basically, I want to take just one sentence from a collection of anything up to (say) 30 sentences contained in one string, so I need a regexp that will find a full stop / period, and work back (or forward, I guess) until it finds another, and strip that out into another string.
However, if there is only one full stop / period (ie. only one sentence in the block of text, or maybe none (if the user can't punctuate properly), it would have to figure that out too, and return the whole lot...
Basically:
Then I need to take that sentence and get rid of anything between either square brackets or HTML tags (including the brackets themselves), so if the $sentence was 'Bob was <i>happy</i>.' I'd need to change it to 'Bob was happy.'
Anyone?
Basically, I want to take just one sentence from a collection of anything up to (say) 30 sentences contained in one string, so I need a regexp that will find a full stop / period, and work back (or forward, I guess) until it finds another, and strip that out into another string.
However, if there is only one full stop / period (ie. only one sentence in the block of text, or maybe none (if the user can't punctuate properly), it would have to figure that out too, and return the whole lot...
Basically:
Code: Select all
$sentence = preg_strip("lots/of/clever/stuff", $blockoftext);Anyone?