コード例 #1
0
 /**
  *  This function returns the XML as a string.
  *
  *  @param $pretty  (Optional) Returns the "pretty" version of the XML - with indentation.
  *
  *  @returns  The XML code as a string.
  */
 function toString($pretty = true)
 {
     return "<?xml version=\"" . $this->version . "\" encoding=\"" . $this->encoding . "\"?>" . ($pretty ? "\n" : "") . trim(parent::toString($pretty));
 }
コード例 #2
0
<?php

// include xml library
include_once 'lib.xml.inc.php';
// convert an rdf item to an associative array
function asArray($item)
{
    $a = array();
    while ($item) {
        $a[$item->nodeName] = $item->firstChild->nodeValue;
        $item = $item->nextSibling;
    }
    return $a;
}
// get the feed
$rss = new _XML('http://sourceforge.net/export/rss2_projsummary.php?group_id=84936');
// get article items
$items = $rss->getElementsByTagName('item');
// loop through items and gather download info
$downloads = 1270;
foreach ($items as $k => $item) {
    $a = asArray($item->firstChild);
    if (preg_match("/Downloadable\\ files\\: (\\d+)\\ total\\ downloads/is", $a['title'], $matches)) {
        $downloads += $matches[1];
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>