Master:
# 1    how to retrieve news rss with php 4                  
webfun
Online no
State
Grouping Member
Class class4
Score 156
Wealth 123
Posts 102
Login 03:47:39
one of my web site is still using php4, i see it support domxml anyway. Is it hard to retrieve news feed? e.g., http://au.rss.biz.yahoo.com/financenews/rss/financenews.xml
Hits: 1227, Date: 2009-05-02 04:16:20
[Agree] ( 16 ) [Against] ( 15 )

# 2    I did this before, I post full source codes here now                  
exp
Online no
State
Grouping Member
Class class4
Score 348
Wealth 219
Posts 269
Login 11:49:09
Code:
$file = "http://au.rss.biz.yahoo.com/financenews/rss/financenews.xml";
$xml_prop = domxml_open_file($file);
$root = $xml_prop->document_element();
$nodes = $root->child_nodes();
$needed = 10;
$count = 0;
foreach($nodes as $node){
if ($node->node_name()=='channel'){
$nodes2 = $node->child_nodes();
foreach($nodes2 as $node2){
if ($node2->node_name() == 'item'){
$nodes3 = $node2->child_nodes();
foreach($nodes3 as $node3){
if($node3->node_name()=='title')
$title = $node3->get_content();
if($node3->node_name()=='link')
$link = $node3->get_content();
}
if($count<$needed){
echo $title;
$count++;
}
}
}
}
}

Hits: 1224, Date: 2009-05-04 08:04:08
[Agree] ( 13 ) [Against] ( 12 )

# 3    php 5 is better now                  
luke1
Online no
State 453
Grouping Super Admin
Class class4
Score 250
Wealth 62
Posts 230
Login 07:37:57
don't need to do this kind of tedious things.
Hits: 1213, Date: 2009-05-08 06:51:23
[Agree] ( 13 ) [Against] ( 12 )

# 4    try to use simplexml                  
exp
Online no
State
Grouping Member
Class class4
Score 348
Wealth 219
Posts 269
Login 11:49:09
it is supported by new php now, I have just found it is hard to navigate the attribute values. i will give a concrete example later.
Hits: 1198, Date: 2009-05-28 04:32:52
[Agree] ( 12 ) [Against] ( 12 )

# 5    a good example of using simplexml                  
exp
Online no
State
Grouping Member
Class class4
Score 348
Wealth 219
Posts 269
Login 11:49:09
http://www.ibm.com/developerworks/library/x-simplexml.html

It is easy to following the idea for beginner.
Hits: 1163, Date: 2009-08-31 23:03:13
[Agree] ( 10 ) [Against] ( 10 )

# 6    # 2 is not bad anyway, i am still using it for a client!                  
exp
Online no
State
Grouping Member
Class class4
Score 348
Wealth 219
Posts 269
Login 11:49:09
# 2 is not bad anyway, i am still using it for a client!
Hits: 1160, Date: 2009-09-01 01:42:08
[Agree] ( 10 ) [Against] ( 10 )

# 7    a hint to hide the broswer error from domxml_open_file                  
exp
Online no
State
Grouping Member
Class class4
Score 348
Wealth 219
Posts 269
Login 11:49:09
you can create coding like this:
if($xml_prop=domxml_open_file($file,DOMXML_LOAD_PARSING);
display content here ...
)
else
echo "";//display nothing, error will be hidden.
Hits: 1158, Date: 2009-09-06 23:38:42
[Agree] ( 10 ) [Against] ( 10 )

# 8    this is important if you want to retrieve remote file                  
exp
Online no
State
Grouping Member
Class class4
Score 348
Wealth 219
Posts 269
Login 11:49:09
the remote file is slow to be loaded, it it is not complete and valid, errors could be displayed in browser.

you can create coding like this:
if($xml_prop=domxml_open_file($file,DOMXML_LOAD_PARSING);
display content here ...
)
else
echo "";//display nothing, error will be hidden. Posted by: exp

Hits: 1157, Date: 2009-09-06 23:40:25
[Agree] ( 10 ) [Against] ( 10 )

# 9    domxml_open_file is good, i still use it                  
exp
Online no
State
Grouping Member
Class class4
Score 348
Wealth 219
Posts 269
Login 11:49:09
domxml_open_file is good, i still use it
Hits: 1122, Date: 2009-12-07 09:20:50
[Agree] ( 4 ) [Against] ( 4 )

# 10    Thanks, exp, this is what i want                  
Dude
Online no
State
Grouping Member
Class class4
Score 161
Wealth 125.5
Posts 116
Login 00:20:49
Thanks, exp, this is what i want
Hits: 1119, Date: 2009-12-16 02:26:36
[Agree] ( 4 ) [Against] ( 4 )

# 11    Retrieve attribute with simplexml                  
Dude
Online no
State
Grouping Member
Class class4
Score 161
Wealth 125.5
Posts 116
Login 00:20:49
$xml->attributes()->q;

if attribute name is q and the current node is $xml, for example,

<link q="test"></link>
Hits: 1098, Date: 2010-03-18 06:22:24
[Agree] ( 3 ) [Against] ( 3 )

# 12    Another trick is tag name                  
Dude
Online no
State
Grouping Member
Class class4
Score 161
Wealth 125.5
Posts 116
Login 00:20:49
if your tag name contains something like - : you may need a special syntax to iterate the value.

foreach($xml->tag-name as $item){
echo $item->pbs:title;
}

The above does not work!

The correct one is:
foreach($xml->{'tag-name'} as $item){
echo $item->{'pbs:title'};
}
Tags: ec
Hits: 1096, Date: 2010-03-18 06:32:48
[Agree] ( 3 ) [Against] ( 3 )

# 13    # 12 is not really right sorry                  
Dude
Online no
State
Grouping Member
Class class4
Score 161
Wealth 125.5
Posts 116
Login 00:20:49
# 12 is not really right sorry
Hits: 1094, Date: 2010-03-18 08:59:31
[Agree] ( 3 ) [Against] ( 3 )

# 14    if the XML is NOT designed by you, and has some special tag name, you may need ...                  
exp
Online no
State
Grouping Member
Class class4
Score 348
Wealth 219
Posts 269
Login 11:49:09
use the following loop to iterate something like this: In the title part, there is no more node. You can foreach more if there are more nodes.
Hits: 1090, Date: 2010-03-18 20:54:22
[Agree] ( 3 ) [Against] ( 3 )

# 15    domxml_open_file does not work in php 5 now!!!                  
luke1
Online no
State 453
Grouping Super Admin
Class class4
Score 250
Wealth 62
Posts 230
Login 07:37:57
domxml_open_file does not work in php 5 now!!!
Hits: 833, Date: 2011-06-11 11:43:52
[Agree] ( 1 ) [Against] ( 1 )

# 16    I recommend DOMDocument for php 5                  
luke1
Online no
State 453
Grouping Super Admin
Class class4
Score 250
Wealth 62
Posts 230
Login 07:37:57
I recommend DOMDocument for php 5
Hits: 830, Date: 2011-06-11 11:44:56
[Agree] ( 1 ) [Against] ( 1 )

1 - 16 [ 16]

Reply: how to retrieve news rss with php 4

*First line:


More content:


Tags:



Hint: You cannot post here before loginLogin | Register

nothing