Welcome to WebmasterWorld Guest from 54.211.62.139

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

How can I limit the length a piece of text?

Is there a simple command for this?

     
2:44 pm on Mar 30, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 8, 2000
posts:52
votes: 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.

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

Junior Member

10+ Year Member

joined:Dec 8, 2000
posts:52
votes: 0


Never mind - I figure it out:

substr($var,0,$limit)
3:06 pm on Mar 30, 2004 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12541
votes: 1


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

one minute too slow ;)

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

Junior Member

joined:Apr 27, 2003
posts:131
votes: 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.

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 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.