Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to read tags from an xml file

    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!!!!!!!

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,468
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    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 Code:
    <?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;

    ?>
    Last edited by mlseim; 07-06-2007 at 10:15 PM.

  • #3
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Am I missing something? Isn't that exactly whats going on with $data?
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #5
    New Coder
    Join Date
    Jul 2007
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by hasanatkazmi View Post
    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?
    PHP and MYSQL
    $string = "3Ip*hKEpanKI#8dmUys&*KqlIJ*P8D";
    $new_string = ereg_replace("[^a-z]", "", $string);
    echo "<a href=http://www.$new_string.org>$new_string</a>";


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •