You are here: Re: [PHP] Looking for a string function « PHP « IT news, forums, messages
Re: [PHP] Looking for a string function

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация