From 7d2ccc978620d2e04cc47cf3c0679a0f254bb9db Mon Sep 17 00:00:00 2001 From: Jeroen van Wolffelaar Date: Sun, 5 Aug 2001 22:49:38 +0000 Subject: [PATCH] Fix examles (whitespace between funcname and parameters), and a few entities git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@53504 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/strings.xml | 117 +++++++++++++++++++++--------------------- 1 file changed, 59 insertions(+), 58 deletions(-) diff --git a/functions/strings.xml b/functions/strings.xml index b4c4031762..a50558f7e5 100644 --- a/functions/strings.xml +++ b/functions/strings.xml @@ -1,5 +1,5 @@ - + String functions Strings @@ -22,7 +22,7 @@ - AddCSlashes + addcslashes Quote string with slashes in a C style @@ -55,7 +55,7 @@ <function>addcslashes</function> example -$escaped = addcslashes ($not_escaped, "\0..\37!@\177..\377"); +$escaped = addcslashes($not_escaped, "\0..\37!@\177..\377"); @@ -101,7 +101,7 @@ echo addcslashes("zoo['.']", 'z..A'); - AddSlashes + addslashes Quote string with slashes @@ -169,7 +169,7 @@ echo addcslashes("zoo['.']", 'z..A'); <function>chop</function> example -$trimmed = chop ($line); +$trimmed = chop($line); @@ -206,11 +206,11 @@ $trimmed = chop ($line); <function>chr</function> example -$str .= chr (27); /* add an escape character at the end of $str */ +$str .= chr(27); /* add an escape character at the end of $str */ /* Often this is more useful */ -$str = sprintf ("The string ends in escape: %c", 27); +$str = sprintf("The string ends in escape: %c", 27); This function complements ord. See also @@ -252,7 +252,7 @@ $str = sprintf ("The string ends in escape: %c", 27); # format $data using RFC 2045 semantics -$new_string = chunk_split (base64_encode($data)); +$new_string = chunk_split(base64_encode($data)); This function is significantly faster than @@ -560,7 +560,7 @@ echo $foo,$bar; // foobarbarbaz // However, the following examples will work: ($some_var) ? print('true'): print('false'); // print is a function -echo ($some_var) ? 'true': 'false'; // changing the statement around +echo $some_var ? 'true': 'false'; // changing the statement around ?> @@ -623,7 +623,7 @@ I have <?=$foo?> foo. <function>explode</function> example $pizza = "piece1 piece2 piece3 piece4 piece5 piece6"; -$pieces = explode (" ", $pizza); +$pieces = explode(" ", $pizza); @@ -681,9 +681,9 @@ $pieces = explode (" ", $pizza); Translation Table Example -$trans = get_html_translation_table (HTML_ENTITIES); +$trans = get_html_translation_table(HTML_ENTITIES); $str = "Hallo & <Frau> & Krämer"; -$encoded = strtr ($str, $trans); +$encoded = strtr($str, $trans); The $encoded variable will now contain: "Hallo @@ -696,8 +696,8 @@ $encoded = strtr ($str, $trans); the direction of the translation. -$trans = array_flip ($trans); -$original = strtr ($str, $trans); +$trans = array_flip($trans); +$original = strtr($str, $trans); The content of $original would be: "Hallo & @@ -970,7 +970,7 @@ $new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES); <function>implode</function> example -$colon_separated = implode (":", $array); +$colon_separated = implode(":", $array); @@ -1465,7 +1465,7 @@ echo "</PRE>\n"; <function>ord</function> example -if (ord ($str) == 10) { +if (ord($str) == 10) { echo "The first character of \$str is a line feed.\n"; } @@ -1636,7 +1636,7 @@ echo $second[1]; /* prints "another" */ <function>rtrim</function> example -$trimmed = rtrim ($line); +$trimmed = rtrim($line); @@ -1841,12 +1841,12 @@ echo "<author id='$id'> Soundex Examples -soundex ("Euler") == soundex ("Ellery") == 'E460'; -soundex ("Gauss") == soundex ("Ghosh") == 'G200'; -soundex ("Hilbert") == soundex ("Heilbronn") == 'H416'; -soundex ("Knuth") == soundex ("Kant") == 'K530'; -soundex ("Lloyd") == soundex ("Ladd") == 'L300'; -soundex ("Lukasiewicz") == soundex ("Lissajous") == 'L222'; +soundex("Euler") == soundex("Ellery") == 'E460'; +soundex("Gauss") == soundex("Ghosh") == 'G200'; +soundex("Hilbert") == soundex("Heilbronn") == 'H416'; +soundex("Knuth") == soundex("Kant") == 'K530'; +soundex("Lloyd") == soundex("Ladd") == 'L300'; +soundex("Lukasiewicz") == soundex("Lissajous") == 'L222'; @@ -2027,7 +2027,7 @@ printf($format,$num,$location); <function>sprintf</function>: zero-padded integers -$isodate = sprintf ("%04d-%02d-%02d", $year, $month, $day); +$isodate = sprintf("%04d-%02d-%02d", $year, $month, $day); @@ -2037,7 +2037,7 @@ $money1 = 68.75; $money2 = 54.35; $money = $money1 + $money2; // echo $money will output "123.1"; -$formatted = sprintf ("%01.2f", $money); +$formatted = sprintf("%01.2f", $money); // echo $formatted will output "123.10" @@ -2110,7 +2110,7 @@ $formatted = sprintf ("%01.2f", $money); $var1 = "Hello"; $var2 = "hello"; -if (!strcasecmp ($var1, $var2)) { +if (!strcasecmp($var1, $var2)) { echo '$var1 is equal to $var2 in a case-insensitive string comparison'; } @@ -2421,7 +2421,7 @@ if (!strcasecmp ($var1, $var2)) { below: -$arr1 = $arr2 = array ("img12.png","img10.png","img2.png","img1.png"); +$arr1 = $arr2 = array("img12.png","img10.png","img2.png","img1.png"); echo "Standard string comparison\n"; usort($arr1,"strcmp"); print_r($arr1); @@ -2655,14 +2655,14 @@ print str_pad($input, 10, "_", STR_PAD_BOTH); // produces "__Alien___" // in PHP 4.0b3 and newer: -$pos = strpos ($mystring, "b"); +$pos = strpos($mystring, "b"); if ($pos === false) { // note: three equal signs // not found... } // in versions older than 4.0b3: -$pos = strpos ($mystring, "b"); -if (is_string ($pos) && !$pos) { +$pos = strpos($mystring, "b"); +if (is_string($pos) && !$pos) { // not found... } @@ -2724,11 +2724,11 @@ if (is_string ($pos) && !$pos) { <function>strrchr</function> example // get last directory in $PATH -$dir = substr (strrchr ($PATH, ":"), 1); +$dir = substr(strrchr($PATH, ":"), 1); // get everything after last newline $text = "Line 1\nLine 2\nLine 3"; -$last = substr (strrchr ($text, 10), 1 ); +$last = substr(strrchr($text, 10), 1 ); @@ -2761,7 +2761,7 @@ $last = substr (strrchr ($text, 10), 1 ); <function>str_repeat</function> example -echo str_repeat ("-=", 10); +echo str_repeat("-=", 10); @@ -2828,14 +2828,14 @@ echo str_repeat ("-=", 10); // in PHP 4.0b3 and newer: -$pos = strrpos ($mystring, "b"); +$pos = strrpos($mystring, "b"); if ($pos === false) { // note: three equal signs // not found... } // in versions older than 4.0b3: -$pos = strrpos ($mystring, "b"); -if (is_string ($pos) && !$pos) { +$pos = strrpos($mystring, "b"); +if (is_string($pos) && !$pos) { // not found... } @@ -2880,7 +2880,7 @@ if (is_string ($pos) && !$pos) { The line of code: -$var = strspn ("42 is the answer, what is the question ...", "1234567890"); +$var = strspn("42 is the answer, what is the question ...", "1234567890"); will assign 2 to $var, because the string "42" will @@ -2930,7 +2930,7 @@ $var = strspn ("42 is the answer, what is the question ...", "1234567890"); <function>strstr</function> example $email = 'sterling@designmultimedia.com'; -$domain = strstr ($email, '@'); +$domain = strstr($email, '@'); print $domain; // prints @designmultimedia.com @@ -2966,10 +2966,10 @@ print $domain; // prints @designmultimedia.com <function>strtok</function> example $string = "This is an example string"; -$tok = strtok ($string," "); +$tok = strtok($string," "); while ($tok) { echo "Word=$tok<br>"; - $tok = strtok (" "); + $tok = strtok(" "); } @@ -3015,7 +3015,7 @@ while ($tok) { Note that 'alphabetic' is determined by the current locale. This means that in i.e. the default "C" locale, characters such as - umlaut-A (Ä) will not be converted. + umlaut-A (Ä) will not be converted. <function>strtolower</function> example @@ -3058,7 +3058,7 @@ print $str; # Prints mary had a little lamb and she loved it so <function>strtoupper</function> example $str = "Mary Had A Little Lamb and She LOVED It So"; -$str = strtoupper ($str); +$str = strtoupper($str); print $str; # Prints MARY HAD A LITTLE LAMB AND SHE LOVED IT SO @@ -3118,7 +3118,7 @@ print $str; # Prints MARY HAD A LITTLE LAMB AND SHE LOVED IT SO <function>str_replace</function> example -$bodytag = str_replace ("%body%", "black", "<body text=%body%>"); +$bodytag = str_replace("%body%", "black", "<body text=%body%>"); @@ -3183,7 +3183,7 @@ $addr = strtr($addr, " Examples: -$trans = array ("hello" => "hi", "hi" => "hello"); +$trans = array("hello" => "hi", "hi" => "hello"); echo strtr("hi all, I said hello", $trans) . "\n"; @@ -3235,8 +3235,8 @@ echo strtr("hi all, I said hello", $trans) . "\n"; Examples: -$rest = substr ("abcdef", 1); // returns "bcdef" -$rest = substr ("abcdef", 1, 3); // returns "bcd" +$rest = substr("abcdef", 1); // returns "bcdef" +$rest = substr("abcdef", 1, 3); // returns "bcd" @@ -3248,9 +3248,9 @@ $rest = substr ("abcdef", 1, 3); // returns "bcd" Examples: -$rest = substr ("abcdef", -1); // returns "f" -$rest = substr ("abcdef", -2); // returns "ef" -$rest = substr ("abcdef", -3, 1); // returns "d" +$rest = substr("abcdef", -1); // returns "f" +$rest = substr("abcdef", -2); // returns "ef" +$rest = substr("abcdef", -3, 1); // returns "d" @@ -3274,7 +3274,7 @@ $rest = substr ("abcdef", -3, 1); // returns "d" Examples: -$rest = substr ("abcdef", 1, -1); // returns "bcde" +$rest = substr("abcdef", 1, -1); // returns "bcde" @@ -3370,18 +3370,18 @@ $var = 'ABCDEFGH:/MNRPQR/'; echo "Original: $var<hr>\n"; /* These two examples replace all of $var with 'bob'. */ -echo substr_replace ($var, 'bob', 0) . "<br>\n"; -echo substr_replace ($var, 'bob', 0, strlen ($var)) . "<br>\n"; +echo substr_replace($var, 'bob', 0) . "<br>\n"; +echo substr_replace($var, 'bob', 0, strlen($var)) . "<br>\n"; /* Insert 'bob' right at the beginning of $var. */ -echo substr_replace ($var, 'bob', 0, 0) . "<br>\n"; +echo substr_replace($var, 'bob', 0, 0) . "<br>\n"; /* These next two replace 'MNRPQR' in $var with 'bob'. */ -echo substr_replace ($var, 'bob', 10, -1) . "<br>\n"; -echo substr_replace ($var, 'bob', -7, -1) . "<br>\n"; +echo substr_replace($var, 'bob', 10, -1) . "<br>\n"; +echo substr_replace($var, 'bob', -7, -1) . "<br>\n"; /* Delete 'MNRPQR' from $var. */ -echo substr_replace ($var, '', 10, -1) . "<br>\n"; +echo substr_replace($var, '', 10, -1) . "<br>\n"; ?> @@ -3447,12 +3447,12 @@ echo substr_replace ($var, '', 10, -1) . "<br>\n"; Note that 'alphabetic' is determined by the current locale. For instance, in the default "C" locale characters such as umlaut-a - (ä) will not be converted. + (ä) will not be converted. <function>ucfirst</function> example $text = 'mary had a little lamb and she loved it so.'; -$text = ucfirst ($text); // $text is now Mary had a little lamb +$text = ucfirst($text); // $text is now Mary had a little lamb // and she loved it so. @@ -3625,4 +3625,5 @@ sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: +vim: ts=1 sw=1 et syntax=sgml -->