Ciao a tutti.
Dunque io ho il parsing in php di un file xml, che mi restituisce in formato html delle news in tempo reale da un altro sito.
Questo il codice:
<?phpcodice:nv
class xItem {
var $xTitle;
var $xLink;
var $xDescription;
}
$sTitle = "";
$sLink = "";
$sDescription = "";
$arItems = array();
$itemCount = 0;
$uFile = "http://www.blablabla.it/rss/homepage/rss2.0.xml";
$bDesc = true;
$uFont = "Verdana, Arial, Helvetica, sans-serif";
$uFontSize = "2";
function startElement($parser, $name, $attrs) {
global $curTag;
$curTag .= "^$name";
}
function endElement($parser, $name) {
global $curTag;
$caret_pos = strrpos($curTag,'^');
$curTag = substr($curTag,0,$caret_pos);
}
function characterData($parser, $data) { global $curTag;
global $sTitle, $sLink, $sDescription;
$titleKey = "^RSS^CHANNEL^TITLE";
$linkKey = "^RSS^CHANNEL^LINK";
$descKey = "^RSS^CHANNEL^DESCRIPTION";
if ($curTag == $titleKey) {
$sTitle = $data;
}
elseif ($curTag == $linkKey) {
$sLink = $data;
}
elseif ($curTag == $descKey) {
$sDescription = $data;
}
global $arItems, $itemCount;
$itemTitleKey = "^RSS^CHANNEL^ITEM^TITLE";
$itemLinkKey = "^RSS^CHANNEL^ITEM^LINK";
$itemDescKey = "^RSS^CHANNEL^ITEM^DESCRIPTION";
if ($curTag == $itemTitleKey) {
$arItems[$itemCount] = new xItem();
$arItems[$itemCount]->xTitle = $data;
}
elseif ($curTag == $itemLinkKey) {
$arItems[$itemCount]->xLink = $data;
}
elseif ($curTag == $itemDescKey) {
$arItems[$itemCount]->xDescription = $data;
$itemCount++;
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($uFile,"r"))) {
die ("could not open RSS for input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
?>
<html>
<head>
<title><?php echo ($sTitle); ?></title>
<meta name = "description" content = "<?php echo ($sDescription); ?>">
<link href="foglio.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor = "#FFFFFF">
<table width="100" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="news">
<?php
for ($i=0;$i<count($arItems);$i++) {
$txItem = $arItems[$i];
?>
<font face = "<?php echo($uFont); ?>" size = "<?php echo($uFontSize); ?>"><a class="base" href = "<?php echo($txItem->xLink); ?>"><?php echo($txItem->xTitle); ?></a></font>
<?php
if ($bDesc) {
?>
<font face = "<?php echo($uFont); ?>" size = "<?php echo($uFontSize); ?>"><?php echo ($txItem->xDescription); ?></font>
<?php
}
echo ("
");
}
?>
</td>
</tr>
</table>
</body>
</html>
[/CODE]
Ora io queste news vorrei farle scorrere con un dhtml che ho trovato qui.
La domanda è in che modo inserire la parte di codice php, ossia il 'ciclo for' che impagina i risultati nella variabile del dhtml che lo deve far scorrere?
Grazie e scusate (sono un novello)![]()