Re: Looking for a string function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Nov 02, 2005 at 02:35:47PM -0700, Phillip S. Baker wrote:
> I seem to remember a built in php function that will take a huge block of
> text.
> Then just spit out X number of characters from it and follow it with an
> additional string value.
> But I cannot remember what it is.

I don't know if there's a built-in PHP function to do what you want, but
I wrote this function for one of the sites I run that does the same
thing. Feel free to use it (or expand it to use a custom 'cut off'
string) if you want.

function crop_text($text, $max_length)
{
         return strlen($text) > $max_length ? substr($text, 0,
$max_length - 3) 
. '...' : $text;
}

$excerpt = crop_text($input_text, 200);

Paul

-- 
Rogue Tory
http://www.roguetory.org.uk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux