#43494 [Opn]: [PATCH] str_trunc - truncate string without break it
| From: | felipe@php.net | Date: | Mon, 10 Dec 2007 01:24:26 +0000 |
| Subject: | #43494 [Opn]: [PATCH] str_trunc - truncate string without break it | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-120509@lists.php.net to get a copy of this message | ||
ID: 43494
User updated by: felipe@php.net
-Summary: [PATCH] str_truncate - truncate string without break it
Reported By: felipe@php.net
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] felipe@php.net
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