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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted August 10, 2008 Share Posted August 10, 2008 do echo htmlentities($retval); Quote Link to comment 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'); ?> Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.