[thelist] finding the period after X chars
tim
tim at hyperlinkage.com
Sat Dec 23 06:26:56 CST 2006
Brian Cummiskey wrote:
> I'm looking to take the first say, 200 characters or so, but I want it
> to run out until the next instance of a "." (period) is found, so as to
> make a complete sentence.
I would do it with a regular expression. Something like (in PHP):
$pattern = "/.{0,200}.*?\./";
if( preg_match( $pattern, $fullText, $matches ) )
{
$shortText = $matches[ 0 ];
print $shortText;
}
This regex basically reads "0 - 200 characters, followed by some more
characters (lazy), followed by a dot".
Hope this helps,
Tim
--
http://www.hyperlinkage.com/
More information about the thelist
mailing list