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