General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 24th, 2003, 12:24 PM
GandalfTheBrown GandalfTheBrown is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 9 GandalfTheBrown User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Displaying first 20 words.

I have a mysql database. I want to have, a sort of "intro" to each article for my site at www.geekswithpcs.com. I want to know the variable to display the frist, say 20-30 words of the article, ON my interface, then i want to have a "Read More..." button. So, my question is as follows, what is the variable or command FOR the displaying for about 20-30 words, from a mysql cell?

Reply With Quote
  #2  
Old September 24th, 2003, 02:34 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Check out http://us2.php.net/manual/en/function.wordwrap.php. There are any number of ways you could do this, but I hadn't run across this function before and thought I'd give it a shot. Something like the following code should work. I'm assuming for the sake of this example that your mysql column is in $str.

PHP Code:
 $words=split("|",wordwrap($str,75,"|"));
print 
$words[0]; 


The wordwrap function returns your string cut on word boundaries with the second parameter as the max col count. The third parameter is the character you wish to cut your string with. So you can feed the results of wordwrap to split, splitting on the character you used to cut, and voila, you've got an array whose zero element is, in this case, not more than 75 characters wide.

You could also do something like the following:

PHP Code:
 $words=split(" ",$str);
print 
join(" ",array_slice($words,0,25)); 


This code splits a string into its words and then prints the first 25 elements of the words array.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Displaying first 20 words.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway