SitePoint Sponsor

User Tag List

Results 1 to 22 of 22

Thread: Xml & Php

  1. #1
    Fully Qualified Fool :) luke-innovative's Avatar
    Join Date
    Jun 2002
    Location
    Kent, UK
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Xml & Php

    (another one of my "?? + PHP" threads )

    Can anyone direct me to a decent tutorial of how to integrate XML with PHP. I was planning on using XML to retrieve data from a DB, and then printing it on a PHP page just by using "<message>" or something. Is this actually possible? I wanna be able to do it so that I can modify the design of a page easily.


    Thanks in advance
    Luke
    Luke-Martin.com (work in progress) :: Independent Web Designer's Portal
    Freelance Forums :: Sign Up Here
    "What happens if you get scared half to death twice?"

  2. #2
    SitePoint Wizard Rick's Avatar
    Join Date
    Oct 2002
    Location
    Lancashire, UK
    Posts
    3,847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    K Yanks Parsing XML with PHP article might help - its here: http://www.webmasterbase.com/article/560

    The code is to parse an RSS feed with PHP, but can be easily adapted

    Good luck

    Rick
    Rick

  3. #3
    Fully Qualified Fool :) luke-innovative's Avatar
    Join Date
    Jun 2002
    Location
    Kent, UK
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I'll have a look
    Luke
    Luke-Martin.com (work in progress) :: Independent Web Designer's Portal
    Freelance Forums :: Sign Up Here
    "What happens if you get scared half to death twice?"

  4. #4
    SitePoint Wizard Rick's Avatar
    Join Date
    Oct 2002
    Location
    Lancashire, UK
    Posts
    3,847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No probs

    Good luck

    Rick
    Rick

  5. #5
    SitePoint Zealot t0m|ta's Avatar
    Join Date
    Mar 2002
    Location
    Madrid - Spain
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi I hope this is a correct thread to ask :-)

    I'm trying to generate an rss file with php just like it is done here at site point :-)

    I've read kevin Yank article, but it deals with how to parse an already generated rss file, and what I want to do is to generate one and I'm having a silly problem

    PHP interprets the xml declaration as being php code (<?xml version="1.0" encoding="iso-8859-1" ?>) and of course I get a parse error.

    I've tried the manual and kevin's book, but I'm getting a bit lost, żDoes any one know how to avoid this?

    Thanks :-)

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    have a look at the url below.. it shows you how to create an rss/xml feed

    http://www.developers-resources.com/.../07/08/8945895

    lemme know if u get it to work, as i had a problem whereby it would not save anything to the cache.rss file.

  7. #7
    SitePoint Zealot t0m|ta's Avatar
    Join Date
    Mar 2002
    Location
    Madrid - Spain
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you very much, it looks like a very good tutorial to me :-), I'll give it a try this afternoon after work, and tell you if I get it to work

    Thanks very much :-)

  8. #8
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's a nice set of XML classes at: http://phpxmlclasses.sourceforge.net - well documented and have examples.

  9. #9
    SitePoint Zealot t0m|ta's Avatar
    Join Date
    Mar 2002
    Location
    Madrid - Spain
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks harry :-)

    The first script did not work for me, it gave no error whatsoever but it did not write anything into cache.rss either so my "newsfeeds" consisted of "1".

    When I first read about this it seemed so easy.... two non sleeping nights after, I think i've changed my mind about the difficulties XD

  10. #10
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i know what you mean. i spent ages trying to find out what was wrong, but could not find anything. as there were no errors, that made it even more difficult.

    have a look another url below. dunno if it will help.



    http://www.phpdeveloper.org/our_scripts.php

  11. #11
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by t0m|ta
    Thanks harry :-)

    The first script did not work for me, it gave no error whatsoever but it did not write anything into cache.rss either so my "newsfeeds" consisted of "1".

    When I first read about this it seemed so easy.... two non sleeping nights after, I think i've changed my mind about the difficulties XD
    Hi i just got the script from the 1st url i sent to work. what i did was to copy the database connection info into the cache_feed.php file & that seem to have done that trick. it has written the cache.rss with the info ...

    Brilliant.

  12. #12
    SitePoint Zealot t0m|ta's Avatar
    Join Date
    Mar 2002
    Location
    Madrid - Spain
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, sorry I havent answered before, but on weekends i usually to into the middle of nowhere and have no conection, so I havent worked on it very much, I'm having a "well formedness" problem and I think it is because of the php type urls of the links ".php?id=variable&shat=sfd.

    I still have to investigate, i did not understad very well the error explanations, found them too spread in litle bits and to technical but I'll keep looking.

    The rss validator came along very useful :-)

    I'll keep informing

  13. #13
    SitePoint Zealot
    Join Date
    Oct 2002
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem here might be caused by the & in the URL which is used to mark an XML-entity.

    Try to change the variable-separator in your PHP-config.
    include_once('./sig.inc.php');

  14. #14
    SitePoint Zealot t0m|ta's Avatar
    Join Date
    Mar 2002
    Location
    Madrid - Spain
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't is a hosted site I thought it might be that, :-(

    So I think I'll have to take a look at how to rewrite URLS of twhich there are a couple here

    Snif all this work

    Thanks to you all :_)

  15. #15
    SitePoint Zealot
    Join Date
    Oct 2002
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The PHP manual shows that arg_separator.input has a modifier of PHP_INI_PERDIR which means that you can set it via a .htaccess file and arg_separator.output can be modified either by .htaccess or ini_set().
    include_once('./sig.inc.php');

  16. #16
    SitePoint Zealot t0m|ta's Avatar
    Join Date
    Mar 2002
    Location
    Madrid - Spain
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes thanks, I have two tutorials here, i have to read and implement them :-)

    I promess the moment I have the code working I'll post it

  17. #17
    SitePoint Zealot t0m|ta's Avatar
    Join Date
    Mar 2002
    Location
    Madrid - Spain
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works!!! :-)

    To avoid having to deal with multidimensional arrays, i've used a SELECT twice, so once I've got that solved it'll be ready :-)

    Thanks!!!

    http://www.tomatoma.ws/prueba3.php

  18. #18
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    which script did u use ?

  19. #19
    SitePoint Wizard Mincer's Avatar
    Join Date
    Mar 2001
    Location
    London | UK
    Posts
    1,140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by t0m|ta
    PHP interprets the xml declaration as being php code (<?xml version="1.0" encoding="iso-8859-1" ?>) and of course I get a parse error.
    For that, you need to disable short open tags in php.ini.

  20. #20
    SitePoint Zealot t0m|ta's Avatar
    Join Date
    Mar 2002
    Location
    Madrid - Spain
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the end I studied all others and made my own script, because i think that's the only way to really learn what you are doing :-)

    It is still in th "reapeated query" stage as to be able to query only once and use the results twice, I have to study how to put the results in an array and how to use a multidimensional array; and that'll take me some time as I'm a lawyer completely lacking in computing background

    Please, do not laugh at me, here is the script :-)

    PHP Code:
    <?php echo('<?xml version="1.0" encoding="iso-8859-1"?>');
    include(
    '/mypath/connect.inc');
    include(
    '/mypath/variables.php');
    ?>
    <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns="http://purl.org/rss/1.0/">

    <channel rdf:about="http://www.tomatoma.ws">
        <title>Instrucciones de andar por casa</title>
        <link>[url]http://www.tomatoma.ws[/url]</link>
         <description>::..:: tomatoma ::..:: Instrucciones de andar por casa... para los que no distinguimos una cafetera de un ordenador...</description> 
          <dc:language>es-ES</dc:language>
          <dc:creator>webmaster@tomatoma.ws</dc:creator> 
      <admin:generatorAgent rdf:resource="http://www.oreillynet.com/pub/a/network/2000/08/25/magazine/rss_tut.html" />
    - <items>
        - <rdf:Seq>
    <?php
    $sql 
    "SELECT topic_id,topic_title,topic_time,topic_views, username, forum_id FROM manual_topics, phpbb_users WHERE forum_id <> 3 AND forum_id <> 11 AND forum_id <> 1 AND forum_id <> 25 AND forum_id <> 24  AND forum_id <> 13  AND user_id = topic_poster  ORDER BY topic_time DESC LIMIT 0, 15";
    $rs = @mysql_query($sql);
         if (!
    $rs) {
            echo (
    "Error en la query 1");
            exit();
        }
        while (
    $row = @mysql_fetch_row($rs))
         {  
     
    $topic[$e]['topic_id'] = $row["0"];
     
    $topic[$e]['topic_title']= $row["1"];
     
    $topic[$e]['topic_time'] = date('d.m.y',$row["2"]);
     
    $topic[$e]['topic_views'] = $row["3"];
     
    $topic[$e]['username']= $row["4"];
      
    $topic[$e]['forum_id']= $row["5"];
    ?> 
        <rdf:li rdf:resource="http://www.tomatoma.ws/articulo.php/topic_id/<?php echo $topic[$e]['topic_id'] . "/forum_id/" $topic[$e]['forum_id'];?>/" /> 
    <?php
        
    }
    ?>
    </rdf:Seq>
      </items>
      </channel>
    <?php

    $result 
    = @mysql_query($sql);
         if (!
    $result) {
            echo (
    "Error en la query 1");
            exit();
        }
     while (
    $row = @mysql_fetch_row($result))

        {  
     
    $topic[$e]['topic_id'] = $row["0"];
     
    $topic[$e]['topic_title']= $row["1"];
     
    $topic[$e]['topic_time'] = date('d.m.y',$row["2"]);
     
    $topic[$e]['topic_views'] = $row["3"];
     
    $topic[$e]['username']= $row["4"];
      
    $topic[$e]['forum_id']= $row["5"];
    ?>
    <item rdf:about="http://www.tomatoma.ws/articulo.php/topic_id/<?php echo $topic[$e]['topic_id'] . "/forum_id/" $topic[$e]['forum_id'];?>/">
                      <title><?php echo$topic[$e]['topic_title'];?></title> 
                    <link>[url]http://www.tomatoma.ws/articulo.php/topic_id/[/url]<?php echo $topic[$e]['topic_id'] . "/forum_id/" $topic[$e]['forum_id'];?>/</link> 
                     <dc:creator><?php echo  $topic[$e]['username'];?></dc:creator> 
                      
      </item>
    <?php     ?>
    </rdf:RDF>
    I promess I'll continue studying :-)

    PS: I know, the query is not even optimized to the data I need :-), that's my next goal.

    Best regards
    Last edited by t0m|ta; Nov 19, 2002 at 10:40.

  21. #21
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cool..

    btw, i found the following short script that can parse xml/rss headlines

    PHP Code:
    <?php 
    $xmlfile 
    fopen("http://www.yournewsfile.rss/or.xml""r"); 
    if(!
    $xmlfile)die("Sorry cannot open the xml/rss file"); 
    $readfile fread($xmlfile ,40000); 
    $searchfile eregi("<item>(.*)</item>"$readfile ,$arrayreg); 
    $filechunks explode("<item>"$arrayreg[0]); 
    $count count($filechunks); 
    for(
    $i=$i<=$count-;$i++) 

    ereg("<title>(.*)</title>",$filechunks[$i], $title); 
    ereg("<link>(.*)</link>",$filechunks[$i], $links); 
    echo 
    "<li>"
    echo 
    "<a href ='$links[1]'\>$title[1]</a>"
    echo 
    "</li>"

    ?>

  22. #22
    SitePoint Zealot t0m|ta's Avatar
    Join Date
    Mar 2002
    Location
    Madrid - Spain
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice and short, for parsing rss i'm using kevin Yank's

    It works nicely, and he even explains how it works. It's got two version, OOP and functions version :-)


Bookmarks

Posting Permissions

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