turtleflame Posted November 7, 2011 Share Posted November 7, 2011 I'm getting this error message: "Parse error: syntax error, unexpected '>' in php2.php on line 49" in regards to this line of code: echo "<h2>$country</h2><ul>"; can't figure out what the problem is. Any ideas? Thanks. (I pasted the entire script below.) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Multidimensional Arrays</title> </head> <body> <p>Some North American States, Provinces, and Territories:</p> <?php # Script 2.7 - multi.php // Create one array: $mexico = array( 'YU' => 'Yucatan', 'BC' => 'Baja California', 'OA' => "Oaxaca' ); // Create another array: $us = array ( 'MD' => 'Maryland', 'IL' => 'Illinois', 'PA' => 'Pennsylvania', 'IA' => 'Iowa' ); // Create a third array: $canada = array ( 'QC' => 'Quebec', 'AB' => 'Alberta', 'NT' => 'Northwest Territories', 'YT' => 'Yukon', 'PE' => 'Prince Edward Island' ); // Combine the arrays: $n_america = array( 'Mexico' => $mexico, 'United States' => $us, 'Canada' => $canada ); // Loop through the countries: foreach ($n_america as $country => $list) { // Print a heading: echo "<h2>$country</h2></ul>"; // Print each state, province, or territory: foreach ($list as $k => $v) { echo "<li>$k - $v</li>\n"; // Close the list: echo '</ul>; } // End of main FOREACH ?> </body> </html> Link to comment Share on other sites More sharing options...
Jonathon Posted November 7, 2011 Share Posted November 7, 2011 Miss matched quotes on the first array Link to comment Share on other sites More sharing options...
turtleflame Posted November 7, 2011 Author Share Posted November 7, 2011 Thanks. Fixed that. Also caught the missing " ' " re: </ul>. It's still not working though. Link to comment Share on other sites More sharing options...
Jonathon Posted November 7, 2011 Share Posted November 7, 2011 (edited) What's the error or problem? Oh yeah think your missing a brace too Edited November 7, 2011 by Jonathon Link to comment Share on other sites More sharing options...
turtleflame Posted November 7, 2011 Author Share Posted November 7, 2011 Also changed </ul> to <ul> where the opening tag was supposed to be. Link to comment Share on other sites More sharing options...
turtleflame Posted November 7, 2011 Author Share Posted November 7, 2011 Parse error: syntax error, unexpected $end in php2.php on line 61 Link to comment Share on other sites More sharing options...
Jonathon Posted November 7, 2011 Share Posted November 7, 2011 Yep, missing brace '}' Link to comment Share on other sites More sharing options...
turtleflame Posted November 7, 2011 Author Share Posted November 7, 2011 Got it. Thank you! Link to comment Share on other sites More sharing options...
Jonathon Posted November 7, 2011 Share Posted November 7, 2011 How did your code end up, because it will display properly if you just put the brace at the bottom of the code, but the source code will be wrong. Link to comment Share on other sites More sharing options...
turtleflame Posted November 7, 2011 Author Share Posted November 7, 2011 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Multidimensional Arrays</title> </head> <body> <p>Some North American States, Provinces, and Territories:</p> <?php # Script 2.7 - multi.php // Create one array: $mexico = array( 'YU' => 'Yucatan', 'BC' => 'Baja California', 'OA' => 'Oaxaca' ); // Create another array: $us = array ( 'MD' => 'Maryland', 'IL' => 'Illinois', 'PA' => 'Pennsylvania', 'IA' => 'Iowa' ); // Create a third array: $canada = array ( 'QC' => 'Quebec', 'AB' => 'Alberta', 'NT' => 'Northwest Territories', 'YT' => 'Yukon', 'PE' => 'Prince Edward Island' ); // Combine the arrays: $n_america = array( 'Mexico' => $mexico, 'United States' => $us, 'Canada' => $canada ); // Loop through the countries: foreach ($n_america as $country => $list) { // Print a heading: echo "<h2>$country</h2><ul>"; // Print each state, province, or territory: foreach ($list as $k => $v) { echo "<li>$k - $v</li>\n"; } // Close the list: echo '</ul>'; } // End of main FOREACH. ?> </body> </html> Link to comment Share on other sites More sharing options...
Jonathon Posted November 7, 2011 Share Posted November 7, 2011 All good! Link to comment Share on other sites More sharing options...
Recommended Posts