I'm trying to trim string in quite non-standard way. The text is devided on two parts - visible teaser and hidden rest part which is showing by JS after clicking a link. I need somethink like that: My text:
Teaser: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas enim est, convallis non ullamcorper hendrerit, vehicula ac quam. In malesuada suscipit eleifend. Rest: Donec posuere ipsum at ipsum feugiat eu ornare nunc ultricies. Donec eleifend odio a eros semper cursus. Donec posuere ipsum at ipsum feugiat eu ornare nunc ultricies. Donec eleifend odio a eros semper cursus.
My problem is because all the text is stored in single field in database. In need to trim teaser after dwo dots or 100 characters and then show the rest part of text (whithout loosing any character). The "rest" part must start with new sentence and big letter like in above example.
If I would use substr on the text the rest will start with random letter...
$text = '';
$text = strip_tags($row['text']);
$text = explode('.', $text);
$teaser = $text[0].$text[1].'.';
$cut = strlen($teaser);
if($cut > 100)
{
$teaser = trimString($text, 0, 100);
$cut = 100;
}
$theRest = substr($row['text'], $cut);
With this I have teaser ending with "." or "..." (my function trimString works like that) and this is good. But the rest in this scenario starts with random letter and this is not what i want. I'm afraid that someone would use dot in the middle of sentence which will cause another problems. Any ideas?