socialmatrix Posted August 10, 2008 Share Posted August 10, 2008 Hello, please consider following code: $retval = '<value>'; $retval .= $_GET['num1'] + $_GET['num2']; $retval .= '</value>'; echo "$retval"; num1 = 1 and num2 = 2. on the browser, $retval echoes 3 (gets rid of XML tags). I want to modify this code to echo "<value>3</value>". what do I need to do? Thank You, Thekdi Link to comment https://forums.phpfreaks.com/topic/119001-solved-keep-xml-tags/ Share on other sites More sharing options...
ratcateme Posted August 10, 2008 Share Posted August 10, 2008 it does but the browser tries to phrase the tags so they wont be displayed use firefox and view the source you will find them there Scott. Link to comment https://forums.phpfreaks.com/topic/119001-solved-keep-xml-tags/#findComment-612778 Share on other sites More sharing options...
genericnumber1 Posted August 10, 2008 Share Posted August 10, 2008 do echo htmlentities($retval); Link to comment https://forums.phpfreaks.com/topic/119001-solved-keep-xml-tags/#findComment-612792 Share on other sites More sharing options...
PFMaBiSmAd Posted August 10, 2008 Share Posted August 10, 2008 If the file does not have a .xml extension, you will need to add the following line of code to cause the browser to treat the content as xml - <?php header('Content-Type: text/xml'); ?> Link to comment https://forums.phpfreaks.com/topic/119001-solved-keep-xml-tags/#findComment-612796 Share on other sites More sharing options...
socialmatrix Posted August 10, 2008 Author Share Posted August 10, 2008 Thank You Scott, genericnumber1 and PFMaBiSmAd, @Scott: yeah but I was hoping , browse to treat content as XML @genericnumber1: that works . However, display is still HTML. I am hoping to make browser look like what we get via RSS feeds. e.g. http://rss.cnn.com/rss/cnn_topstories.rss . OR even better if you use del.icio.us, they have a service https://api.del.icio.us/v1/posts/get? this returns XML data. This is what I want to do. @PFMaBiSmAd: I thought your solution would solve above problem. However, it doesn't. Returned content is still HTML. Any mor esuggestions? Thanks a lot again, Thekdi Link to comment https://forums.phpfreaks.com/topic/119001-solved-keep-xml-tags/#findComment-612801 Share on other sites More sharing options...
ratcateme Posted August 10, 2008 Share Posted August 10, 2008 have you put this at the top <?xml version="1.0" encoding="UTF-8"?> make sure you echo them like this echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; other wise it will be put as PHP Scott. Link to comment https://forums.phpfreaks.com/topic/119001-solved-keep-xml-tags/#findComment-612802 Share on other sites More sharing options...
genericnumber1 Posted August 10, 2008 Share Posted August 10, 2008 Yes, and don't follow my earlier advice if you wish for it to be xml. I thought you just wanted to display xml in an html web page. Link to comment https://forums.phpfreaks.com/topic/119001-solved-keep-xml-tags/#findComment-612803 Share on other sites More sharing options...
socialmatrix Posted August 10, 2008 Author Share Posted August 10, 2008 Thanks a lot again for consistent help. Something very strange happened, I have echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; at the top. But it doesn't get echoed at all. Previously, I had print '<?xml version="1.0"?>'; This never used print either! Link to my service is: http://azvaishnav.info/app/index.php?method=addIt&num1=1&num2=2 Here I am calling addIt function that adds num1 and num2. Do you think problem might be because I use godaddy? may be I should set up Apache Tomcat? Thank You, Thekdi Link to comment https://forums.phpfreaks.com/topic/119001-solved-keep-xml-tags/#findComment-612807 Share on other sites More sharing options...
genericnumber1 Posted August 10, 2008 Share Posted August 10, 2008 No, that echo is coming through okay, but it's a tag and won't be displayed. Also, tomcat is for jsp/servlets, so no... that wouldn't help. this is being echo'd: </object></layer></span></div></table></body></html><!-- adsok --> <script language='javascript' src='https://a12.alphagodaddy.com/hosting_ads/gd01.js'></script> You need to stop that from being sent. Are you sure you put header('Content-Type: text/xml'); at the top of your script? my browser is still reporting it as text/html Link to comment https://forums.phpfreaks.com/topic/119001-solved-keep-xml-tags/#findComment-612811 Share on other sites More sharing options...
ratcateme Posted August 10, 2008 Share Posted August 10, 2008 if it still wont work try using the header header('Content-Type: application/xml'); godaddy might handle it differently Scott. Link to comment https://forums.phpfreaks.com/topic/119001-solved-keep-xml-tags/#findComment-612814 Share on other sites More sharing options...
socialmatrix Posted August 10, 2008 Author Share Posted August 10, 2008 Yeah, this is the first few lines of my script. <?php header('Content-Type: application/xml'); echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; But browser is still reporting it as text/html. Here's the link again. Link to comment https://forums.phpfreaks.com/topic/119001-solved-keep-xml-tags/#findComment-613109 Share on other sites More sharing options...
socialmatrix Posted August 11, 2008 Author Share Posted August 11, 2008 thank you Scott, genericnumber1, PFMaBiSmAd, I don't know why, but I installed Apache and tried the same file through that with localhost. and It solved my problem. Appreciate your considerations. Thekdi Link to comment https://forums.phpfreaks.com/topic/119001-solved-keep-xml-tags/#findComment-613178 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.