corillo181 Posted October 8, 2007 Share Posted October 8, 2007 how do i limit a paragraph to a set number. like if i got a strory and i only want 15 words to show how would i do it? i got it stared but ran out of idea. <?php function shortBio($id,$length){ $query="SELECT bio FROM tra_artist WHERE artist_id='$id'"; $result=$this->db->query($query); $txt = $this->db->fetch_array($result); $newtxt =explode(" ",$txt['bio']); $count = count($newtxt); } ?> Link to comment https://forums.phpfreaks.com/topic/72229-solved-word-counter/ Share on other sites More sharing options...
teng84 Posted October 8, 2007 Share Posted October 8, 2007 http://www.php.net/manual/en/function.wordwrap.php Link to comment https://forums.phpfreaks.com/topic/72229-solved-word-counter/#findComment-364218 Share on other sites More sharing options...
pocobueno1388 Posted October 8, 2007 Share Posted October 8, 2007 <?php $newtxt =explode(" ",$txt['bio']); for ($i=0; $i<15; $i++){ echo $newtxt[$i].' '; } ?> There could be a better way...but that works. Teng84 - They didn't say they wanted 15 words per LINE, they want 15 words total. At least from what I understand. Link to comment https://forums.phpfreaks.com/topic/72229-solved-word-counter/#findComment-364219 Share on other sites More sharing options...
corillo181 Posted October 8, 2007 Author Share Posted October 8, 2007 thats wha ti have in mind but how do i put that in a return? Link to comment https://forums.phpfreaks.com/topic/72229-solved-word-counter/#findComment-364221 Share on other sites More sharing options...
teng84 Posted October 8, 2007 Share Posted October 8, 2007 <?php $newtxt =explode(" ",$txt['bio']); for ($i=0; $i<15; $i++){ echo $newtxt[$i].' '; } ?> There could be a better way...but that works. Teng84 - They didn't say they wanted 15 words per LINE, they want 15 words total. At least from what I understand. ohh yah but this might be usefull look you dont know how long each words Link to comment https://forums.phpfreaks.com/topic/72229-solved-word-counter/#findComment-364222 Share on other sites More sharing options...
teng84 Posted October 8, 2007 Share Posted October 8, 2007 <? function shortBio($id,$length){ $query="SELECT bio FROM tra_artist WHERE artist_id='$id'"; $result=$this->db->query($query); $txt = $this->db->fetch_array($result); $newtxt =explode(" ",$txt['bio']); if (count($newtxt)<15){ return $txt['bio'];} else{ for($x=0;$x<15;$x++){ $words .= $newtxt[$x]; } return $words; } } ?> Link to comment https://forums.phpfreaks.com/topic/72229-solved-word-counter/#findComment-364224 Share on other sites More sharing options...
corillo181 Posted October 8, 2007 Author Share Posted October 8, 2007 yeah man.. i don't know whats wrong with me, it's maybe because the Yankees are loosing that i don't seen to remember anything.. lol Link to comment https://forums.phpfreaks.com/topic/72229-solved-word-counter/#findComment-364225 Share on other sites More sharing options...
pocobueno1388 Posted October 8, 2007 Share Posted October 8, 2007 yeah man.. i don't know whats wrong with me, it's maybe because the Yankees are loosing that i don't seen to remember anything.. lol Yeah, that can do it =] The Broncos lost tonight, and I'm still angry Link to comment https://forums.phpfreaks.com/topic/72229-solved-word-counter/#findComment-364228 Share on other sites More sharing options...
teng84 Posted October 8, 2007 Share Posted October 8, 2007 solved? Link to comment https://forums.phpfreaks.com/topic/72229-solved-word-counter/#findComment-364230 Share on other sites More sharing options...
corillo181 Posted October 8, 2007 Author Share Posted October 8, 2007 yes solved :| man people can't express anger in here.. anyways Yankees got the lead so now i can work calmly !!!! Link to comment https://forums.phpfreaks.com/topic/72229-solved-word-counter/#findComment-364232 Share on other sites More sharing options...
teng84 Posted October 8, 2007 Share Posted October 8, 2007 men i cant relate with your yankesssssss maybe post your expression in our miscellaneous section Link to comment https://forums.phpfreaks.com/topic/72229-solved-word-counter/#findComment-364234 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.