vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Truncate Variable (https://vborg.vbsupport.ru/showthread.php?t=122808)

rogersnm 08-02-2006 09:13 AM

Truncate Variable
 
I have searched far and wide but can not find the answer xD

ok, so, how do i truncate (trim) characters off a string so it could have been x characters before but is 10 now?

Regards,
Nick.

Paul M 08-02-2006 09:28 AM

<a href="http://uk.php.net/substr" target="_blank">substr()</a>

rogersnm 08-02-2006 09:31 AM

so:
PHP Code:

substr($str05); 

will limit it to 5 characters

is there an if so if it is more than x characers then do this and do this eg:
PHP Code:

if ($str something)
{
substr($str05);
$str $str "...";



Paul M 08-02-2006 09:36 AM

Yes (but no quotes needed around $str).

rogersnm 08-02-2006 09:44 AM

ok but what about the second bit?

Paul M 08-02-2006 09:51 AM

Second bit ?

rogersnm 08-02-2006 10:01 AM

PHP Code:

if ($str something)
{
substr($str05);
$str $str "...";


What do i put for if ($str something) to only do that if the string is more than 5 characters long?

Guest190829 08-02-2006 10:30 AM

Quote:

Originally Posted by rogersnm
PHP Code:

if ($str something)
{
substr($str05);
$str $str "...";


What do i put for if ($str something) to only do that if the string is more than 5 characters long?

PHP Code:

if (strlen($str) > 5)
{
   
//string is greater than 5 chars


Also whitespace counts, so you may want to think about trimming the whitespace from the string beforehand. :)

And here is a list of all php string functions, which could come in handy:

http://us2.php.net/manual/en/ref.strings.php

rogersnm 08-02-2006 10:30 AM

thanks :)

ok so i have:
PHP Code:

if (strlen($posttitle) > 30)
{
substr($posttitle030);
$posttitle $posttitle "...";
}  

if (
strlen($postforumname) > 30)
{
substr($postforumname030);
$postforumname $postforumname "...";


but the variables just show up empty

Paul M 08-02-2006 10:36 AM

You have to assign the substr to something.

$var = substr(.....)


All times are GMT. The time now is 05:02 PM.

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.01153 seconds
  • Memory Usage 1,745KB
  • 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
  • (6)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete