|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-07-21 17:06 UTC] jason at jasonsw dot com
Description: ------------ It would be great if there was a way to limit the amount of characters that were trimmed from a string, in either ltrim, trim or rtrim, using a new limit parameter. Reproduce code: --------------- --- From manual page: function.ltrim --- Patchesfeature-49007.diff (last revision 2011-02-27 10:10 UTC by jthijssen at noxlogic dot nl)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 17 08:00:01 2025 UTC |
I've added a patch (both 5.3 and trunk) for adding a "limit" to the [lr]?trim() functions. Using a limit of -1 will trim all (same as without adding the limit) A limit of 0 does nothing (no trimming) A positive limit will only trim the amount of chars as specified ON BOTH SIDES. This means using a limit of 2 in trim() will strip max 2 chars from the left and max 2 chars from the right: trim(" hello ", " ", 2) returns " hello "; ltrim(" hello ", " ", 2) returns " hello "; The only problem to keep it backwards compatible is that you must add the default charlist ( \n\r\t\v\0) in order to use the limit parameter.