php.net |  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: felipe@php.net Assigned:
Status: Suspended Package: Strings related
PHP Version: 5.3CVS-2007-12-04 (CVS) OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
9 + 33 = ?
Subscribe to this entry?

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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-08 21:17 UTC] jani@php.net
-Package: Feature/Change Request +Package: Strings related
 [2020-03-31 17:16 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2020-03-31 17:16 UTC] cmb@php.net
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] <https://www.php.net/mailing-lists.php#internals>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 15:01:32 2024 UTC