-2

What's wrong with my PHP? I go to sandwiches.php?type=2 and all I see is cheeseavocadospinach, not the XML tags with the values.

<?php
header("Content-type: text/xml");
if ($_GET["type"] == "1")
  $sandwiches = array('ham', 'turkey', 'cheese');
if ($_GET["type"] == "2")
  $sandwiches = array('cheese', 'avocado', 'spinach');
echo '<?xml version="1.0"?>';
echo '<sandwiches>';
foreach ($sandwiches as $value)
{
  echo '<sandwich>';
  echo $value;
  echo '</sandwich>';
}
echo '</sandwiches>';
?>

Please help.

Thanks

Neo
  • 51
  • 5
  • Look at the page source. – LMC May 01 '22 at 21:30
  • What's wrong with it? – Neo May 01 '22 at 21:31
  • 2
    Nothing's wrong with it, that's the point - your browser is showing you the text content, assuming the tags are just markup; view source, and you'll see the XML is there just fine. – IMSoP May 01 '22 at 21:35
  • Does this answer your question? [Display HTML snippets in HTML](https://stackoverflow.com/questions/2820453/display-html-snippets-in-html) – CBroe May 02 '22 at 07:37

1 Answers1

0

The XML characters show up when you view source.

Neo
  • 51
  • 5