{"id":333,"date":"2013-03-11T15:05:14","date_gmt":"2013-03-11T15:05:14","guid":{"rendered":"http:\/\/a1webdesignteam.com\/blog\/?p=333"},"modified":"2013-03-11T15:05:14","modified_gmt":"2013-03-11T15:05:14","slug":"display-xml-content-php-header","status":"publish","type":"post","link":"https:\/\/a1webdesignteam.com\/blog\/display-xml-content-php-header\/","title":{"rendered":"To Display XML content using PHP Header"},"content":{"rendered":"<p>Nowadays web services are become more and more popular and Most commonly used format for exchanging information in web services are XML because XML is simple to use and easy to read tag structures.<\/p>\n<p>In this tutorial,I will show you how you read read XML in PHP using header content type.The header informs the browser which type of document it is so the browser can render it as per that.<\/p>\n<p>Let\u2019s understand the code:<\/p>\n<p>First of all, let\u2019s generate xml code.<\/p>\n<div id=\"crayon-513df266d8078\" data-settings=\" minimize scroll-mouseover\">\n<div><textarea readonly=\"readonly\" wrap=\"off\" data-settings=\"dblclick\">$xml = &#8216;&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;iso-8859-1&#8243;?&gt;&#8217;;<br \/>\n$xml .= &#8216;&lt;categories&gt;&lt;category&gt;&#8217;;<br \/>\n$xml .= &#8216;&lt;ID&gt;1&lt;\/ID&gt;&#8217;;<br \/>\n$xml .= &#8216;&lt;CategoryName&gt;PHP&lt;\/CategoryName&gt;&#8217;;<br \/>\n$xml .= &#8216;&lt;\/category&gt;&#8217;;<br \/>\n$xml .= &#8216;&lt;category&gt;&#8217;;<br \/>\n$xml .= &#8216;&lt;ID&gt;2&lt;\/ID&gt;&#8217;;<br \/>\n$xml .= &#8216;&lt;CategoryName&gt;Wordpress&lt;\/CategoryName&gt;&#8217;;<br \/>\n$xml .= &#8216;&lt;\/category&gt;&#8217;;<br \/>\n$xml .= &#8216;&lt;\/categories&gt;&#8217;;<\/textarea><\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td data-settings=\"show\">\n<div>\n<div data-line=\"crayon-513df266d8078-1\">1<\/div>\n<div data-line=\"crayon-513df266d8078-2\">2<\/div>\n<div data-line=\"crayon-513df266d8078-3\">3<\/div>\n<div data-line=\"crayon-513df266d8078-4\">4<\/div>\n<div data-line=\"crayon-513df266d8078-5\">5<\/div>\n<div data-line=\"crayon-513df266d8078-6\">6<\/div>\n<div data-line=\"crayon-513df266d8078-7\">7<\/div>\n<div data-line=\"crayon-513df266d8078-8\">8<\/div>\n<div data-line=\"crayon-513df266d8078-9\">9<\/div>\n<div data-line=\"crayon-513df266d8078-10\">10<\/div>\n<div data-line=\"crayon-513df266d8078-11\">11<\/div>\n<\/div>\n<\/td>\n<td>\n<div>\n<div id=\"crayon-513df266d8078-1\"><\/div>\n<div id=\"crayon-513df266d8078-2\">$xml = &#8216;&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;iso-8859-1&#8243;?&gt;&#8217;;<\/div>\n<div id=\"crayon-513df266d8078-3\">$xml .= &#8216;&lt;categories&gt;&lt;category&gt;&#8217;;<\/div>\n<div id=\"crayon-513df266d8078-4\">$xml .= &#8216;&lt;ID&gt;1&lt;\/ID&gt;&#8217;;<\/div>\n<div id=\"crayon-513df266d8078-5\">$xml .= &#8216;&lt;CategoryName&gt;PHP&lt;\/CategoryName&gt;&#8217;;<\/div>\n<div id=\"crayon-513df266d8078-6\">$xml .= &#8216;&lt;\/category&gt;&#8217;;<\/div>\n<div id=\"crayon-513df266d8078-7\">$xml .= &#8216;&lt;category&gt;&#8217;;<\/div>\n<div id=\"crayon-513df266d8078-8\">$xml .= &#8216;&lt;ID&gt;2&lt;\/ID&gt;&#8217;;<\/div>\n<div id=\"crayon-513df266d8078-9\">$xml .= &#8216;&lt;CategoryName&gt;Wordpress&lt;\/CategoryName&gt;&#8217;;<\/div>\n<div id=\"crayon-513df266d8078-10\">$xml .= &#8216;&lt;\/category&gt;&#8217;;<\/div>\n<div id=\"crayon-513df266d8078-11\">$xml .= &#8216;&lt;\/categories&gt;&#8217;;<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Next, main part of code is header, need to write header to read xml content.To display XML file on browser use Content-type: <code>text\/xml<\/code> header.<\/p>\n<div id=\"crayon-513df266d80c2\" data-settings=\" minimize scroll-mouseover\">\n<div><textarea readonly=\"readonly\" wrap=\"off\" data-settings=\"dblclick\">header (&#8220;Last-Modified: &#8221; . gmdate(&#8220;D,d M YH:i:s&#8221;) . &#8221; GMT&#8221;);<br \/>\nheader (&#8220;Cache-Control: no-cache, must-revalidate&#8221;);<br \/>\nheader (&#8220;Pragma: no-cache&#8221;);<br \/>\nheader (&#8220;Content-type: text\/xml&#8221;);<br \/>\nheader (&#8220;Content-Description: PHP Generated Data&#8221; );<br \/>\necho $xml;<\/textarea><\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td data-settings=\"show\">\n<div>\n<div data-line=\"crayon-513df266d80c2-1\">1<\/div>\n<div data-line=\"crayon-513df266d80c2-2\">2<\/div>\n<div data-line=\"crayon-513df266d80c2-3\">3<\/div>\n<div data-line=\"crayon-513df266d80c2-4\">4<\/div>\n<div data-line=\"crayon-513df266d80c2-5\">5<\/div>\n<div data-line=\"crayon-513df266d80c2-6\">6<\/div>\n<div data-line=\"crayon-513df266d80c2-7\">7<\/div>\n<\/div>\n<\/td>\n<td>\n<div>\n<div id=\"crayon-513df266d80c2-1\"><\/div>\n<div id=\"crayon-513df266d80c2-2\">header (&#8220;Last-Modified: &#8221; . gmdate(&#8220;D,d M YH:i:s&#8221;) . &#8221; GMT&#8221;);<\/div>\n<div id=\"crayon-513df266d80c2-3\">header (&#8220;Cache-Control: no-cache, must-revalidate&#8221;);<\/div>\n<div id=\"crayon-513df266d80c2-4\">header (&#8220;Pragma: no-cache&#8221;);<\/div>\n<div id=\"crayon-513df266d80c2-5\">header (&#8220;Content-type: text\/xml&#8221;);<\/div>\n<div id=\"crayon-513df266d80c2-6\">header (&#8220;Content-Description: PHP Generated Data&#8221; );<\/div>\n<div id=\"crayon-513df266d80c2-7\">echo $xml;<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>That\u2019s all there is to it.Anyway I hope that helps some of you.If you have any questions please let me know via the comments.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nowadays web services are become more and more popular and Most commonly used format for exchanging information in web services are XML because XML is simple to use and easy to read tag structures. In this tutorial,I will show you how you read read XML in PHP using header content type.The header informs the browser [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[9,3,7],"tags":[],"_links":{"self":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/333"}],"collection":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/comments?post=333"}],"version-history":[{"count":0,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/333\/revisions"}],"wp:attachment":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media?parent=333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/categories?post=333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/tags?post=333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}