|
 |
|
จะเขียนสคริป PHP ให้อ่านข้อมูลจาก Rss ยังไงครับ |
|
 |
|
|
 |
 |
|
Code (PHP)
<?
$arr=array();
$count=0;
$block="ITEM";
$key="";
$value="";
function startxml( $parser , $name, $att)
{
global $key;
$key=$name;
}
function endxml( $parser, $name )
{
global $count;
global $block;
if ($name==$block)
{
$count=$count+1;
}
}
function cdata( $parser, $data )
{
global $key;
global $value;
global $count;
global $arr;
if (strlen($data)>1)
{
$value=$data;
$arr[$count]["$key"]=$value;
}
}
$p=xml_parser_create();
xml_set_element_handler( $p , "startxml" , "endxml");
xml_set_character_data_handler($p, "cdata" );
$fp=fopen("http://www.xyz.com/com_rss.xml","r");
while($data=fread($fp,4096))
{
xml_parse( $p, $data, feof($fp));
}
print("<font size=2></b>");
for ($i=1;$i<5;$i++)
{
echo "<img src=arrow.gif> <a href=", $arr[$i]["LINK"],">";
echo $arr[$i]["TITLE"];
echo "</a>";
echo "<br>";
}
?>
เทคนิค การอ่าน RSS ด้วย PHP แบบง่ายสุดๆ ลองเข้ามาดูกันครับ
|
 |
 |
 |
 |
Date :
2011-07-26 22:22:21 |
By :
thaicreate |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|