From 3c39fa17b324e4e6ffea449155a8ed1edfd3b41b Mon Sep 17 00:00:00 2001 From: Philip Olson Date: Mon, 9 May 2011 18:22:39 +0000 Subject: [PATCH] Clarified removing middle strings via an example and note. Deals with PHP Bug #54697 git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@310860 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/strings/functions/trim.xml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/reference/strings/functions/trim.xml b/reference/strings/functions/trim.xml index 554c878633..1fe837f037 100644 --- a/reference/strings/functions/trim.xml +++ b/reference/strings/functions/trim.xml @@ -144,6 +144,9 @@ var_dump($trimmed); $trimmed = trim($hello, "Hdle"); var_dump($trimmed); +$trimmed = trim($hello, 'HdWr'); +var_dump($trimmed); + // trim the ASCII control characters at the beginning and end of $binary // (from 0 to 31 inclusive) $clean = trim($binary, "\x00..\x1F"); @@ -163,6 +166,7 @@ string(11) "Hello World" string(28) "These are a few words :) ..." string(24) "These are a few words :)" string(5) "o Wor" +string(9) "ello Worl" string(14) "Example string" ]]> @@ -214,12 +218,27 @@ array(3) { + + &reftitle.notes; + + Possible gotcha: removing middle characters + + Because trim trims characters from the beginning and end of + a string, it may be confusing when characters are (or are not) removed from + the middle. trim('abc', 'bad') removes both 'a' and 'b' because it + trims 'a' thus moving 'b' to the beginning to also be trimmed. So, this is why it "works" + whereas trim('abc', 'b') seemingly does not. + + + + &reftitle.seealso; ltrim rtrim + str_replace