# Proposal: str_truncate()

- Thread: https://externals.io/message/33578
- Original archive: https://news-web.php.net/php.internals/33578
- Started by Felipe Pena on 2007-12-02T21:07:54+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #33578 — Felipe Pena — 2007-12-02T21:07:54+00:00

URL: https://externals.io/message/33578#33578

Hi.
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

What you think about it?

Patch: http://ecl.zoone.com.br/etc/patches/str_truncate.patch


--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"


Regards.
-- 
Felipe N. S. Pena
