-MY GOAL is to display the html tags "My page and TESTING on the page" on the same page.
-If I remove the html tags. It give me the XML.
-If I removed the header(‘Content-type: text/xml’); I get only the html and not the xml.
HOW CAN I HAVE BOTH IN THE SAME PAGE.
The code is as follows:
<?php
$test_array = array (
'bla' => 'blub',
'foo' => 'bar',
'overflow' => 'stack',
);
$xml = new SimpleXMLElement('<root/>');
array_walk_recursive($test_array, array ($xml, 'addChild'));
ob_start();
print $xml->asXML();
$xml_output = ob_get_clean();
//header('Content-type: text/xml');
echo $xml_output;
?>
<?php // New PHP block for HTML content ?>
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1>TESTING</h1>
</body>
</html>
/Another try was/
TO put the header as header(‘Content-type: text/json’); //JSON
but here I get the problem whereby it prints the whole html tags
THIS WOULD ALSO BE GOOD FOR ME, IF AM ABLE TO SOLVE THIS
3
Answers
You can’t mix different content types in a single response.
You output a HTML page that displays the other content. However formatting/styling/interaction would all be your job. You need to escape the included content for HTML – like any other variable.
restructuring this a bit:
Should give you this in your browser:
result in the browser
The
<pre>
-Tag tells the browser that this is preformatted text and thehtmlspecialchars()
makes sure to replace<
and>
(open and closing brackets) with HTML entities so that the browser won’t try to interpret this as HTML-Tags, but just as plain text.Hope this helps!
Some links that might be of interest:
If you just need to display html with xml (with tags), use this