vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   how to limit the number of words returned (https://vborg.vbsupport.ru/showthread.php?t=104881)

Sean S 01-09-2006 04:43 PM

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.

sabret00the 01-10-2006 10:57 AM

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:

function return_words($string)
{
    global 
vbulletin;

    
$word 0;
    
    
$string explode(' '$string);

    foreach (
$string AS $key => $value)
    {
        if (
$word == $vbulletin->option['blog_words_returned'])
        {
            break;
        }
        else
        {
            
$string .= " " $value;
        }

        
$word++;
    }

    return 
trim($string);


something like that ;)

Sean S 01-11-2006 06:32 PM

ah I got it working with the substr, thanks you very much :)

Andrew 01-11-2006 07:48 PM

Just out of curiosity how would you limit it to X characters ?

filburt1 01-12-2006 01:06 AM

<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.

Sean S 01-12-2006 11:11 PM

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 :)


All times are GMT. The time now is 04:44 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01016 seconds
  • Memory Usage 1,721KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete