homepage Welcome to WebmasterWorld Guest from 54.242.231.109
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
How can I limit the length a piece of text?
Is there a simple command for this?
ajsinclair




msg:1303707
 2:44 pm on Mar 30, 2004 (gmt 0)
I have a neat little RSS feed parser (using Magpie) that works...

But I want to limit the number of characters of a particular element. Can someone point to me to a php command that does this? I'm a novice.

 

ajsinclair




msg:1303708
 3:05 pm on Mar 30, 2004 (gmt 0)

Never mind - I figure it out:

substr($var,0,$limit)

coopster




msg:1303709
 3:06 pm on Mar 30, 2004 (gmt 0)

You mean something like a substring [php.net]?

one minute too slow ;)

bonanza




msg:1303710
 3:47 pm on Mar 30, 2004 (gmt 0)

Ah, but does anyone have a neat trick to truncate only on a whitespace after a certain number of characters?

I'll be working on a brute-force subroutine to do this, but thought I'd ask in case someone's got a fancy regexp trick or something.

Birdman




msg:1303711
 4:38 pm on Mar 30, 2004 (gmt 0)

$string = "Your feed string here";
$max = 100;
substr($string,0,strpos($string," ",$max));

That will truncate on the first whitespace found starting at the 100th position.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved