Hi, I have PHP script and I want to use the script to write stories but the problem is the story (article) will show in description. I want the description(in source ) be the first 20 words from description For example, like any forum the thread maybe 1000 words but the description just 20 words sorry about my English but I am doing my best
Do it like this: $count= 20; //How many words you want to display $output = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla scelerisque. Nullam posuere sapien. Aenean nec pede quis justo tempus ultrices. Praesent ac purus in quam rhoncus vehicula. Donec varius massa vel nulla. Donec dictum, odio ac volutpat fringilla, nisl ligula lobortis eros, ac congue tortor mauris sit amet quam.'; //Your text $words = explode(' ', $output); //Split every word into an array $words = array_slice($words, 0, $count); //Split the array, so that we only got 20 words. $output= implode(' ', $words); //Join the arrays again to one string. echo $output; PHP:
thank you very much,But excuse me Can you tell me more because I do not know a lot about PHP in the attachment the file that I need to change it can you tell me where I can put php code
Nightcoder, that does only show the first 20 characters. Not the first 20 words. And your echo looks kind of weird. You should just do this: <? echo substr($rfileDescription,0,20); ?> PHP: , no needs for using quotes lol But.. Still use my method: $count= 20; //How many words you want to display $output = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla scelerisque. Nullam posuere sapien. Aenean nec pede quis justo tempus ultrices. Praesent ac purus in quam rhoncus vehicula. Donec varius massa vel nulla. Donec dictum, odio ac volutpat fringilla, nisl ligula lobortis eros, ac congue tortor mauris sit amet quam.'; //Your text $words = explode(' ', $output); //Split every word into an array $words = array_slice($words, 0, $count); //Split the array, so that we only got 20 words. $output= implode(' ', $words); //Join the arrays again to one string. echo $output; PHP:
Nightcoder,elias_sorensen thank you very much but where I can put this code because I do not know PHP
You put the code where you want the 20 words to be displayed Use mine, if you use nightcoder's, you'll only get 20 characters.
thanks for helping meelias_sorensen but I want the 20 words displayed in this file can you do it for me ? because I tried many times http://forums.digitalpoint.com/attachment.php?attachmentid=22450&d=1229002495