"MIchel" <no@spam.please> writes:
[color=blue]
> Yeah. I can do it like that, but it's not quite what I had in mind... there
> has to be a way to do this in a oneliner. something like:[/color]
Right. There HAS to be a way and someone did eventually post one or
more examples.
Why so hell bent on a one liner? I think you will learn from
experience that these one-liners are often terse and unreadable and
merit at least a one-liner comment along with them (we are speaking
about mature, production quality code now).
if(strlen)$input_string) > 15)
{
cut string;
do something special
}
Easy to write, easy to read, self-documenting.
But you wanted a one-liner. Well, here's a tru one-liner using no
regexp and with the test also on the same line.
$string = 'well, hello there !!!';
$length = 15;
if($string !== ($string = substr($string, 0, $length)))
print $string;
YMMV
--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile
http://www.JerrySievers.com/