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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: felipe@php.net
New email:
PHP Version: OS:

 

 [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: Sun Apr 28 06:01:30 2024 UTC