How to display both xml and html in php?

by darrion.kuhn , in category: PHP General , 9 months ago

How to display both xml and html in php?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by scotty_walker , 9 months ago

@darrion.kuhn 

To display both XML and HTML in PHP, you can use the following code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
// XML content
$xml = '<?xml version="1.0"?>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>';

// HTML content
$html = '<!DOCTYPE html>
<html>
<head>
  <title>XML and HTML Display</title>
</head>
<body>
  <h1>Welcome to XML and HTML Display</h1>
  <p>This is an example of displaying both XML and HTML content in PHP.</p>
</body>
</html>';

// Display XML content
header('Content-Type: text/xml');
echo $xml;

// Display HTML content
header('Content-Type: text/html');
echo $html;
?>


This code first defines the XML and HTML content as strings, and then displays them using the header('Content-Type: text/xml') and header('Content-Type: text/html') functions to specify the type of content being output. The echo function is used to output the content to the browser.