bjori Mon Feb 5 13:50:44 2007 UTC
Modified files: /phpdoc/en/reference/strings/functions trim.xml ltrim.xml rtrim.xml Log: Improve *trim() examples Fixes bug#40243 (Clarify that trim(),ltrim(),rtrim() will trim ANY character in charlist) http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/strings/functions/trim.xml?r1=1.10&r2=1.11&diff_format=u Index: phpdoc/en/reference/strings/functions/trim.xml diff -u phpdoc/en/reference/strings/functions/trim.xml:1.10 phpdoc/en/reference/strings/functions/trim.xml:1.11 --- phpdoc/en/reference/strings/functions/trim.xml:1.10 Tue May 31 21:34:35 2005 +++ phpdoc/en/reference/strings/functions/trim.xml Mon Feb 5 13:50:43 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.10 $ --> +<!-- $Revision: 1.11 $ --> <!-- splitted from ./en/functions/strings.xml, last change in rev 1.2 --> <refentry id="function.trim"> <refnamediv> @@ -128,18 +128,44 @@ <![CDATA[ <?php -$text = "\t\tThese are a few words :) ... "; +$text = "\t\tThese are a few words :) ... "; +$binary = "\x09Example string\x0A"; +$hello = "Hello World"; +var_dump($text, $binary, $hello); -echo trim($text); // "These are a few words :) ..." -echo trim($text, " \t."); // "These are a few words :)" +print "\n"; -// trim the ASCII control characters at the beginning and end of $binary +$trimmed = trim($text); +var_dump($trimmed); + +$trimmed = trim($text, " \t."); +var_dump($trimmed); + +$trimmed = trim($hello, "Hdle"); +var_dump($trimmed); + +// trim the ASCII control characters at the beginning of $binary // (from 0 to 31 inclusive) $clean = trim($binary, "\x00..\x1F"); +var_dump($clean); ?> ]]> </programlisting> + &example.outputs; + <screen> +<![CDATA[ +string(32) " These are a few words :) ... " +string(16) " Example string +" +string(11) "Hello World" + +string(28) "These are a few words :) ..." +string(24) "These are a few words :)" +string(5) "o Wor" +string(14) "Example string" +]]> + </screen> </example> </para> <para> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/strings/functions/ltrim.xml?r1=1.6&r2=1.7&diff_format=u Index: phpdoc/en/reference/strings/functions/ltrim.xml diff -u phpdoc/en/reference/strings/functions/ltrim.xml:1.6 phpdoc/en/reference/strings/functions/ltrim.xml:1.7 --- phpdoc/en/reference/strings/functions/ltrim.xml:1.6 Wed Dec 29 17:24:37 2004 +++ phpdoc/en/reference/strings/functions/ltrim.xml Mon Feb 5 13:50:43 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <!-- splitted from ./en/functions/strings.xml, last change in rev 1.2 --> <refentry id="function.ltrim"> <refnamediv> @@ -78,17 +78,45 @@ <?php $text = "\t\tThese are a few words :) ... "; +$binary = "\x09Example string\x0A"; +$hello = "Hello World"; +var_dump($text, $binary, $hello); + +print "\n"; + + $trimmed = ltrim($text); -// $trimmed = "These are a few words :) ... " +var_dump($trimmed); + $trimmed = ltrim($text, " \t."); -// $trimmed = "These are a few words :) ... " -$clean = ltrim($binary, "\x00..\x1F"); -// trim the ASCII control characters at the beginning of $binary +var_dump($trimmed); + +$trimmed = ltrim($hello, "Hdle"); +var_dump($trimmed); + +// trim the ASCII control characters at the beginning of $binary // (from 0 to 31 inclusive) +$clean = ltrim($binary, "\x00..\x1F"); +var_dump($clean); ?> ]]> </programlisting> + &example.outputs; + <screen> +<![CDATA[ +string(32) " These are a few words :) ... " +string(16) " Example string +" +string(11) "Hello World" + +string(30) "These are a few words :) ... " +string(30) "These are a few words :) ... " +string(7) "o World" +string(15) "Example string +" +]]> + </screen> </example> <para> See also <function>trim</function> and <function>rtrim</function>. http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/strings/functions/rtrim.xml?r1=1.6&r2=1.7&diff_format=u Index: phpdoc/en/reference/strings/functions/rtrim.xml diff -u phpdoc/en/reference/strings/functions/rtrim.xml:1.6 phpdoc/en/reference/strings/functions/rtrim.xml:1.7 --- phpdoc/en/reference/strings/functions/rtrim.xml:1.6 Wed Dec 29 17:24:37 2004 +++ phpdoc/en/reference/strings/functions/rtrim.xml Mon Feb 5 13:50:43 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <!-- splitted from ./en/functions/strings.xml, last change in rev 1.31 --> <refentry id="function.rtrim"> <refnamediv> @@ -78,17 +78,43 @@ <?php $text = "\t\tThese are a few words :) ... "; +$binary = "\x09Example string\x0A"; +$hello = "Hello World"; +var_dump($text, $binary, $hello); + +print "\n"; + $trimmed = rtrim($text); -// $trimmed = "\t\tThese are a few words :) ..." +var_dump($trimmed); + $trimmed = rtrim($text, " \t."); -// $trimmed = "\t\tThese are a few words :)" -$clean = rtrim($binary, "\x00..\x1F"); -// trim the ASCII control characters at the end of $binary +var_dump($trimmed); + +$trimmed = rtrim($hello, "Hdle"); +var_dump($trimmed); + +// trim the ASCII control characters at the beginning of $binary // (from 0 to 31 inclusive) +$clean = rtrim($binary, "\x00..\x1F"); +var_dump($clean); ?> ]]> </programlisting> + &example.outputs; + <screen> +<![CDATA[ +string(32) " These are a few words :) ... " +string(16) " Example string +" +string(11) "Hello World" + +string(30) " These are a few words :) ..." +string(26) " These are a few words :)" +string(9) "Hello Wor" +string(15) " Example string" +]]> + </screen> </example> <para> See also <function>trim</function> and <function>ltrim</function>.