Stripping paragraphs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
willmullis
Forum Newbie
Posts: 1
Joined: Wed May 08, 2002 2:05 pm

Stripping paragraphs

Post 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
dusty
Forum Contributor
Posts: 122
Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA

Post 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&#1111;1].";
?>
but there's no sure shot at cutting out a sentence. if something is abbr. then the sentence gets cut off at the ".".
DSM
Forum Contributor
Posts: 101
Joined: Thu May 02, 2002 11:51 am
Location: New Mexico, USA

Post by DSM »

Code: Select all

<? 
$text = "blah blah blah. words words words."; 
$break = explode(".",$text); 
echo "$break&#1111;0]."; 
?>
[0] For first sentence of a paragraph.
dusty
Forum Contributor
Posts: 122
Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA

Post by dusty »

doh thanks for catching that.
User avatar
enygma
Site Admin
Posts: 175
Joined: Fri Apr 19, 2002 8:29 am
Location: Dallas, Tx

Post 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
DSM
Forum Contributor
Posts: 101
Joined: Thu May 02, 2002 11:51 am
Location: New Mexico, USA

Post 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.
User avatar
enygma
Site Admin
Posts: 175
Joined: Fri Apr 19, 2002 8:29 am
Location: Dallas, Tx

Post 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
Post Reply