ID: 43494 User updated by: [EMAIL PROTECTED] -Summary: [PATCH] str_truncate - truncate string without break it Reported By: [EMAIL PROTECTED] Status: Open Bug Type: Feature/Change Request PHP Version: 5.3CVS-2007-12-04 (CVS) New Comment:
Renamed, and updated code: http://ecl.zoone.com.br/etc/patches/str_trunc.patch http://ecl.zoone.com.br/etc/patches/str_trunc.phpt Previous Comments: ------------------------------------------------------------------------ [2007-12-04 10:22:58] [EMAIL PROTECTED] Description: ------------ As posted in Internals, but not answered... 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 Patch: http://ecl.zoone.com.br/etc/patches/str_truncate.patch phpt: http://ecl.zoone.com.br/etc/patches/str_truncate.phpt --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" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43494&edit=1