From 9adf7eba600a7ab91653dc85b9e0b9fb25f1e37d Mon Sep 17 00:00:00 2001 From: Justin Martin Date: Sat, 13 Nov 2010 03:46:44 +0000 Subject: [PATCH] Cleaned up simple string variable parsing example, as per bug #53254. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@305306 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/types/string.xml | 81 +++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/language/types/string.xml b/language/types/string.xml index 7528014c39..750ef67f96 100644 --- a/language/types/string.xml +++ b/language/types/string.xml @@ -513,14 +513,20 @@ EOT; ]]> + &example.outputs; + + + @@ -530,49 +536,48 @@ echo "He drank some {$beer}s"; // works object properties as to simple variables. - + Simple syntax example "purple"); -// Show all errors -error_reporting(E_ALL); +echo "He drank some $juices[0] juice.".PHP_EOL; +echo "He drank some $juices[1] juice.".PHP_EOL; +echo "He drank some juice made of $juice[0]s.".PHP_EOL; +echo "He drank some $juices[koolaid1] juice.".PHP_EOL; -$fruits = array('strawberry' => 'red', 'banana' => 'yellow'); +class people { + public $john = "John Smith"; + public $jane = "Jane Smith"; + public $robert = "Robert Paulsen"; + + public $smith = "Smith"; +} -// Works, but note that this works differently outside a string -echo "A banana is $fruits[banana]."; +$people = new people(); -// Works -echo "A banana is {$fruits['banana']}."; - -// Works, but PHP looks for a constant named banana first, as described below. -echo "A banana is {$fruits[banana]}."; - -// Won't work, use braces. This results in a parse error. -echo "A banana is $fruits['banana']."; - -// Works -echo "A banana is " . $fruits['banana'] . "."; - -// Works -echo "This square is $square->width meters broad."; - -// Won't work. For a solution, see the complex syntax. -echo "This square is $square->width00 centimeters broad."; +echo "$people->john drank some $juices[0] juice.".PHP_EOL; +echo "$people->john then said hello to $people->jane.".PHP_EOL; +echo "$people->john's wife greeted $people->robert.".PHP_EOL; +echo "$people->robert greeted the two $people->smiths."; ?> ]]> - - + &example.outputs; + + + + For anything more complex, you should use the complex syntax.