Okay, i have a news section on a site that has a news sections.
What i want to do is show a shortend preview of the story.
Say i had this text...
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
i want to shorten it so it looks like this
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt...
It must not cut off half way through a word.
I thought about using explode() then itterating through the array a set number of times depending on how many words i want to display in the preview.
Is this the best way?
Thanks
Mark
How to shorten a news story for a preview?
Moderator: General Moderators
what about something like ....
... replace 100 with whatever value you would like the news length to be, should find the next space.
Code: Select all
substr($text,0,strpos($text, " ", "100"))- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Had a quick squiz at the string functions and I think it is probably SUBSTRING_INDEX() that you need:
http://www.mysql.com/doc/en/String_func ... ml#IDX1282
You can use a space as the delimeter and set the number of words you want. Saves taking info out the db that you don't need.
Mac
http://www.mysql.com/doc/en/String_func ... ml#IDX1282
You can use a space as the delimeter and set the number of words you want. Saves taking info out the db that you don't need.
Mac
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK