Proposal: str_truncate()
| From: | Felipe Pena | Date: | Sun, 02 Dec 2007 21:07:54 +0000 |
| Subject: | Proposal: str_truncate() | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-33578@lists.php.net to get a copy of this message | ||
Hi.
I guess interesting have in PHP one function for truncate string
*without break it*, more specifically alphanumeric chars.
PS: wordwrap() works different, see the phpt
What you think about it?
Patch: http://ecl.zoone.com.br/etc/patches/str_truncate.patch
--TEST--
str_truncate
--FILE--
<?php
$str = "Lorem Ipsum is simply dummy text.";
var_dump(str_truncate($str, 25, STR_TRUNC_RIGHT));
var_dump(str_truncate($str, 25, STR_TRUNC_LEFT));
var_dump(str_truncate("foo", 1));
var_dump(str_truncate("foo", 1, 1));
?>
--EXPECT--
string(27) "Lorem Ipsum is simply dummy"
string(22) "Lorem Ipsum is simply "
string(0) ""
string(3) "foo"
Regards.
--
Felipe N. S. Pena