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: 2011-04-08 21:17 UTC
From: felipe@php.net Assigned:
Status: Open Package: Strings related
PHP Version: 5.3CVS-2007-12-04 (CVS) OS:
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [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
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Mon Apr 21 04:01:57 2014 UTC