Page 1 of 1
Stripping paragraphs
Posted: Wed May 08, 2002 2:05 pm
by willmullis
Hey all,
I would like to query the database and if the result comes back with multilple sentences I would like to take the paragraph and strip everything except the first sentence. I'm sure there is a tag out there to do so. I looked through the manual and couldn't come up with much.
Thanks for the help
Posted: Wed May 08, 2002 4:42 pm
by dusty
you could use explode to pick out the first sentence.
Code: Select all
<?
$text = "blah blah blah. words words words.";
$break = explode(".",$text);
echo "$breakї1].";
?>
but there's no sure shot at cutting out a sentence. if something is abbr. then the sentence gets cut off at the ".".
Posted: Wed May 08, 2002 8:22 pm
by DSM
Code: Select all
<?
$text = "blah blah blah. words words words.";
$break = explode(".",$text);
echo "$breakї0].";
?>
[0] For first sentence of a paragraph.
Posted: Wed May 08, 2002 10:14 pm
by dusty
doh thanks for catching that.
Posted: Thu May 09, 2002 7:30 am
by enygma
yes, but remember - if there's anything in that sentence that has a period in it, you're screwed...
for example; "I'm not quite sure that
http://www.phpdn.com is cool enough."
Your example there would have a hayday with that one

-enygma
Posted: Thu May 09, 2002 7:48 am
by DSM
Yup, I have used :
Code: Select all
$text = (substr($body,0,50));
<marquee "attributes"><a href = "url">$text...Click here for full details</a></marquee>
for a scrolling marquee.
This isn't a perfect answer because it may cut a sentence short or may run into the next sentence, but it worked for my purposes.
Posted: Thu May 09, 2002 8:09 am
by enygma
you might also try something like
ereg("^[a-zA-Z]*. ",$body,$output);
I'm not sure if that would work correctly, but it's an idea, since most sentences are generally ended with a period and a space or two...
-enygma