PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old April 28th, 2003, 10:58 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
XML/RSS parsing through PHP

I've been trying to learn how to parse RSS files (http://rss.com.com/2547-12-0-5.xml )


if anybody's dealt with it before, i'm open to any suggestions.

Reply With Quote
  #2  
Old April 28th, 2003, 12:21 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #3  
Old April 28th, 2003, 01:06 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
jpenn,


i was following this tutorial earlier and ran into this problem:


Quote:
Warning: php_hostconnect: connect failed in e:\pub\public_html\rss\sitepointcover.php on line 51

Warning: fopen("http://www.sitepoint.com/rss.php", "r") - Bad file descriptor in e:\pub\public_html\rss\sitepointcover.php on line 51
Error reading RSS data.


Line 51 refers to this:
$fp = fopen("http://www.sitepoint.com/rss.php","r")

i checked the PHP function reference for fopenand "r" is indeed a valid file descriptor... what else might my problem be? I used the code directly from the tutorial, infact... http://www.webmasterbase.com/exampl...over-oo.php.txt links to their source code... i found i had to right click and save as to view it properly.

[for people not reading the tutorial, here's my script:]

PHP Code:
<?php

$insideitem 
false;
$tag "";
$title "";
$description "";
$link "";

function 
startElement($parser$name$attrs) {
    global 
$insideitem$tag$title$description$link;
    if (
$insideitem) {
        
$tag $name;
    } elseif (
$name == "ITEM") {
        
$insideitem true;
    }
}

function 
endElement($parser$name) {
    global 
$insideitem$tag$title$description$link;
    if (
$name == "ITEM") {
        
printf("<dt><b><a href='%s'>%s</a></b></dt>",
            
trim($link),htmlspecialchars(trim($title)));
        
printf("<dd>%s</dd>",htmlspecialchars(trim($description)));
        
$title "";
        
$description "";
        
$link "";
        
$insideitem false;
    }
}

function 
characterData($parser$data) {
    global 
$insideitem$tag$title$description$link;
    if (
$insideitem) {
    switch (
$tag) {
        case 
"TITLE":
        
$title .= $data;
        break;
        case 
"DESCRIPTION":
        
$description .= $data;
        break;
        case 
"LINK":
        
$link .= $data;
        break;
    }
    }
}

$xml_parser xml_parser_create();
xml_set_element_handler($xml_parser"startElement""endElement");
xml_set_character_data_handler($xml_parser"characterData");
$fp fopen("http://www.sitepoint.com/rss.php","r")
    or die(
"Error reading RSS data.");
while (
$data fread($fp4096))
    
xml_parse($xml_parser$datafeof($fp))
        or die(
sprintf("XML error: %s at line %d"
            
xml_error_string(xml_get_error_code($xml_parser)),   
            
xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);

?>

Last edited by MadCowDzz : April 28th, 2003 at 01:09 PM.

Reply With Quote
  #4  
Old April 28th, 2003, 01:55 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Your just pulling my left right?

I just cut and pasted your code just as shown below and it parsed it fine. You could have just hit a spike in the sitepoint connection when you tried. Also, if you are using a firewall and trying this on your development system, that could cause the problem...

Reply With Quote
  #5  
Old April 28th, 2003, 08:15 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
it was the firewall... =)

thanks so much jpenn

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > XML/RSS parsing through PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway