...

View Full Version : how to read tags from an xml file



hasanatkazmi
07-06-2007, 09:49 PM
Hi

i am struct in a problem. i want a $variable to hold all text in an .xml file INCLUDING tags (<tag></tag>) but what ever function i use (file_get_contents, fread etc ) i dont get tags, I dont know how to solve this problem. In PHP documentation I found eregi(), I think this may be usefull but I am not a guru so ..... I need help!!!!!!!

mlseim
07-06-2007, 10:12 PM
I wrote this quick just to test it out ...

It echoes the XML, you could format things better,
but this will be enough to get you started.

It does remove tags in the browser output, but when
you look at the HTML source, you'll see they are there.

XML can't be displayed unless Content-Type is specified,
thus ... my example is showing it like that.



<?php

$url = "http://www.stlukecg.com/podcaster/feed.xml";
$data = implode("", file($url));

//This part outputs the XML - unformatted, it's just a quick
//example so I could display some XML.

echo "header ('Content-Type: text/xml; charset=ISO-8859-1');\n";
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";

echo $data;

?>

hasanatkazmi
07-06-2007, 11:18 PM
Well, thaks for this but my problem is a little more complex, I not only want to display tags but I want to load whole content of xml file including tags in a variable. How can I do so??? Please provide more help

StupidRalph
07-07-2007, 12:33 AM
Am I missing something? Isn't that exactly whats going on with $data?

phpandmysql
07-07-2007, 12:37 AM
Well, thaks for this but my problem is a little more complex, I not only want to display tags but I want to load whole content of xml file including tags in a variable. How can I do so??? Please provide more help

the $data is the variable... Isn't that what you are asking?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum