|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #43494 [PATCH] str_trunc - truncate string without break it
Submitted: 2007-12-04 10:22 UTC Modified: 2020-03-31 17:16 UTC
From: Assigned:
Status: Suspended Package: Strings related
PHP Version: 5.3CVS-2007-12-04 (CVS) OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-12-04 10:22 UTC]
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



$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));

string(27) "Lorem Ipsum is simply dummy"
string(22) "Lorem Ipsum is simply "
string(0) ""
string(3) "foo"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-08 21:17 UTC]
-Package: Feature/Change Request +Package: Strings related
 [2020-03-31 17:16 UTC]
-Status: Open +Status: Suspended
 [2020-03-31 17:16 UTC]
This certainly would require some discussion – whether the
function is wanted at all, and also about details (multibyte
support etc.)  This bug tracker is not suitable for that kind of
discussion, though, so please use the internals@ mailing list[1].
For the time being, I'm suspending this ticket.

[1] <>
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Sep 17 05:03:37 2021 UTC