The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
how to limit the number of words returned
Hi everyone,
I'm working on a little module that lists the latest 5 blog entries of each user. So far I have got the coding part right and it works the way I want to, but there is one thing I don't know how to do and need your help. I would like to only show the first 30 words of the blog entry on the top list, and I don't know how to limit the mysql query to do that. Could anyone tell me how I can achieve that? thank you. |
#2
|
||||
|
||||
substr is the easiest method, but that's characters, you want to limit words then you're gonna have to make a function
PHP Code:
|
#3
|
||||
|
||||
ah I got it working with the substr, thanks you very much
|
#4
|
||||
|
||||
Just out of curiosity how would you limit it to X characters ?
|
#5
|
|||
|
|||
<a href="http://www.php.net/substr" target="_blank">http://www.php.net/substr</a>
Although it's better to limit it in the query. |
#6
|
||||
|
||||
basically here is what I did and it worked for me, first I called the variable in a string, and then I created another variable that outputs the substr function using that string that I created,
$string = "$blogentry"; $rest = substr("$string", 0, 50) . "..."; echo "$rest" basically that 0 is where you want the counting to start, and 50 is the amount that you want to limit. So for me, the counting is going to start from the first (0) character and it's going to stop after the 50th char, and after that it is going to place the "...". Now I'm new to this myself and this way worked for me, someone else here could probably make it work easier than that, hope that helps |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|