|
Posted by Paul Waring on 11/02/05 23:39
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
Navigation:
[Reply to this message]
|