|
|
|
rss ใน IE ไม่มีปัญหา แต่ใน Firefox มีปัญหา ผมมีไฟล์อยู่ 2 ไฟล์ คือ index2.php และ readder2.php เพื่อโชว์ rss ปัญหามันก็มีอยู่ว่า |
|
|
|
|
|
|
|
ผมมีไฟล์อยู่ 2 ไฟล์ คือ index2.php และ readder2.php เพื่อโชว์ rss ปัญหามันก็มีอยู่ว่า เวลา ใช้ ie เปิดก็ปกติ แต่เวลาเปิดกับ Firefox มันไม่แสดงครับ ช่วยดูหน่อยครับ
//index2.php
Code (HTML)
<style>
fieldset {
border:1px solid navy;
width:200px;
padding:5px;
margin:3px;
}
#entertain {
width:100%;
height:180px;
background-image:url(wait.gif);
background-position:center;
background-repeat:no-repeat;
line-height:20px;
font-size:10px;
}
#nectec {
width:100%;
height:180px;
background-image:url(wait.gif);
background-position:center;
background-repeat:no-repeat;
margin:3px;
line-height:20px;
}
fieldset legend {
font-weight:bold;
padding:3px 3px 3px 3px;
}
</style>
<marquee scrollDelay="300">
<div id="travel"></div>
</marquee>
<br /><br />
<script>
function Inint_AJAX()
{
try { return new ActiveXObject("Msxml2.XMLHTTP") } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {} //IE
try { return new XMLHttpRequest() } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported")
return false;
}
function loadNews(url, handle) {
var req = Inint_AJAX()
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
var obj = document.getElementById(handle)
obj.style.backgroundImage = "url()"
obj.style.height='auto'
obj.innerHTML = req.responseText
}
}
}
req.open("POST", "reader2.php", true)
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
req.send("url="+url) //??????
}
window.onload = function () {
loadNews('http://www.worldtravelwatch.com/feed/', 'travel');
}
</script>
Code (PHP)
<?php
<?
$count = 5;
$feedURL = $_POST['url'];
if($feedURL && preg_match("/^https?:\/\/.+$/",$feedURL) && ($feedRef = @fopen($feedURL, 'rb'))) {
$contents = '';
while(!feof($feedRef)) {
$contents .= fread( $feedRef, 8192 );
}
fclose($feedRef);
$charset=getXMLHeader($contents);
if ($charset=="") $charset="UTF-8";
header("content-type: application/x-javascript; charset=$charset"); //????? header ????????? ??? XML ??????????
$rss = RSStoArray($contents); //parse RSS ??????? array
$listcount = $count;
for ($i=0; $i<count($rss) && $listcount>0; $i++) {
echo '<img src="point2.gif" alt="" /> <a href="'.$rss[$i][link][data].'" target="_blank">'.$rss[$i][title][data]."</a> ";
$listcount--;
}
}
//???? header
function getXMLHeader($xml) {
$headers = explode("<?xml", $xml);
$ret="";
for ($i=0; $i<count($headers); $i++) {
$ret.=parseXMLHeader(trim($headers[$i]));
}
return $ret;
}
//?????? attributies ???
function parseXMLHeader($data) {
if ($data!="") {
$EndPos = strpos($data, '?>'); //????? tag ?????? header
$datas = explode(" ", substr($data, 0, $EndPos));
for ($i=0; $i<count($datas); $i++) {
$temps = explode("=", $datas[$i]);
if (trim($temps[0])=='encoding') {
$value = trim($temps[1]);
$value = str_replace('"', '', $value);
$value = str_replace("'", '', $value);
return $value;
}
};
}
return;
}
//?????????? item ???????
function RSStoArray($xml) {
$items = preg_split('/<item[\s|>]/', $xml, -1, PREG_SPLIT_NO_EMPTY);
array_shift($items);
$i = 0;
foreach ($items as $item) {
$array[$i]['title'] = getTextBetweenTags($item, 'title');
$array[$i]['link'] = getTextBetweenTags($item, 'link');
$array[$i]['description'] = getTextBetweenTags($item, 'description');
$array[$i]['author'] = getTextBetweenTags($item, 'author');
$array[$i]['category'] = getTextBetweenTags($item, 'category');
$array[$i]['comments'] = getTextBetweenTags($item, 'comments');
$array[$i]['enclosure'] = getTextBetweenTags($item, 'enclosure');
$array[$i]['guid'] = getTextBetweenTags($item, 'guid');
$array[$i]['pubDate'] = getTextBetweenTags($item, 'pubDate');
$array[$i]['source'] = getTextBetweenTags($item, 'source');
$i++;
}
return $array;
}
//???? tag ??? property
function getTextBetweenTags($text, $tag) {
$StartTag = "<$tag";
$EndTag = "</$tag";
$StartPosTemp = strpos($text, $StartTag);
$StartPos = strpos($text, '>', $StartPosTemp);
$StartPos = $StartPos + 1;
$EndPos = strpos($text, $EndTag);
$StartAttr = $StartPosTemp + strlen($StartTag) + 1;
$EndAttr = $StartPos;
if ($EndAttr > $StartAttr) {
$attribute = substr ($text, $StartAttr, $EndAttr - $StartAttr - 1);
$datas = explode(" ", $attribute);
for ($i=0; $i<count($datas); $i++) {
$temps = explode("=", $datas[$i]);
$name = trim($temps[0]);
if ($name!="/" && $name!="") {
$value = trim($temps[1]);
$value = str_replace('"', '', $value);
$value = str_replace("'", '', $value);
$items[$name] = trim($value);
}
}
};
if($EndPos > $BeginPos) {
$text = substr ($text, $StartPos, ($EndPos - $StartPos));
} else {
$text = '';
}
if (strpos($text, '[CDATA[')==false) {
$text = str_replace('<', '<', $text);
$text = str_replace('>', '>', $text);
$text = str_replace('&', '&', $text);
$text = str_replace('"', '"', $text);
} else {
$text = str_replace('<![CDATA[', '', $text);
$text = str_replace(']]>', '', $text);
}
$items["data"] = trim($text);
return $items;
}
?>
?>
Tag : - - - -
|
|
|
|
|
|
Date :
2009-04-17 15:52:58 |
By :
แท่ง |
View :
1237 |
Reply :
0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|