本文整理汇总了PHP中xml::fetch方法的典型用法代码示例。如果您正苦于以下问题:PHP xml::fetch方法的具体用法?PHP xml::fetch怎么用?PHP xml::fetch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml
的用法示例。
在下文中一共展示了xml::fetch方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dirname
* class_xml.php example usage
* Author: Troy Wolf (troy@troywolf.com)
*/
/*
Include the class. Modify path according to where you put the class file.
*/
require_once dirname(__FILE__) . '/class_xml.php';
/*
Instantiate a new xml object.
*/
$x = new xml();
/*
Pass a string containing your XML to the fetch() method.
*/
$source = file_get_contents("sample.xml");
if (!$x->fetch($source)) {
/*
The class has a 'log' property that contains a log of events. This log is
useful for testing and debugging.
*/
echo "<h2>There was a problem parsing your XML!</h2>";
echo $x->log;
exit;
}
/*
Display the data property's structure and contents.
*/
echo "<pre>\n";
print_r($x->data);
echo "</pre>\n";
/*
示例2: xml
exit;
}
// Note: The following lines can be uncommented to aid in debugging.
#echo "<pre>".$h->log."</pre><hr />\n";
#echo "<pre>".$h->header."</pre><hr />\n";
#echo "<pre>".$h->body."</pre><hr />\n";
#exit();
// Or, these next lines will display the result as an XML doc in the browser.
#header('Content-type: text/xml');
#echo $h->body;
#exit();
// The assumption now is that we've got an XML result back from the Exchange
// Server, so let's parse the XML into an object we can more easily access.
// For this task, we'll use Troy's xml class object.
$x = new xml();
if (!$x->fetch($h->body)) {
echo "<h2>There was a problem parsing your XML!</h2>";
echo "<pre>" . $h->log . "</pre><hr />\n";
echo "<pre>" . $h->header . "</pre><hr />\n";
echo "<pre>" . $h->body . "</pre><hr />\n";
echo "<pre>" . $x->log . "</pre><hr />\n";
exit;
}
// You should now have an object that is an array of objects and arrays that
// makes it easy to access the parts you need. These next lines can be
// uncommented to make a raw display of the data object.
#echo "<pre>\n";
#print_r($x->data);
#echo "</pre>\n";
#exit();
// And finally, an example of iterating the inbox folder names and url's to
示例3: rss20
function rss20($url = "", $ttl = 0, $count = 0)
{
if (!$url) {
echo "<h2>rss20: Oops! You need to pass a URL!</h2>";
return false;
}
/*
Use http object to retrieve raw RSS XML and to cache the data.
Review class_http at http://www.troywolf.com/articles/class_http/
*/
$h = new http();
$h->dir = "../../../../../cache/";
if (!$h->fetch($url, $ttl)) {
/*
The class has a 'log' property that contains a log of events. This log is
useful for testing and debugging.
*/
echo "<h2>There is a problem with the http request!</h2>";
echo $h->log;
exit;
}
/*
Use xml object to parse the raw RSS XML.
Review class_xml at http://www.troywolf.com/articles/class_xml/
*/
$x = new xml();
if (!$x->fetch($h->body)) {
/*
The class has a 'log' property that contains a log of events. This log is
useful for testing and debugging.
*/
echo "<h2>There was a problem parsing your XML!</h2>";
echo $x->log;
exit;
}
/*
Some debugging help.
*/
#echo "<hr />";
#echo $h->log;
#echo "<hr />";
#echo $x->log;
#echo "<pre>\n";
#print_r($x->data);
#echo "</pre>\n";
/*
Now that we have the RSS data parsed into an object, here is how to work with
it.
*/
#$version = $x->data->RSS[0]->_attr->VERSION;
#$channel_link = $x->data->RSS[0]->CHANNEL[0]->LINK[0]->_text;
#$channel_title = $x->data->RSS[0]->CHANNEL[0]->TITLE[0]->_text;
echo "<div class=\"rss\">\n";
echo "<div class=\"head\">\n";
echo "<a href=\"" . $x->data->RSS[0]->CHANNEL[0]->LINK[0]->_text . "\"><img border=\"0\" src=\"" . $x->data->RSS[0]->CHANNEL[0]->IMAGE[0]->URL[0]->_text . "\"" . " alt=\"" . $x->data->RSS[0]->CHANNEL[0]->TITLE[0]->_text . "\" /></a>";
echo "</div>\n";
$total_items = count($x->data->RSS[0]->CHANNEL[0]->ITEM);
if ($count == 0 || $count > $total_items) {
$count = $total_items;
}
for ($idx = 0; $idx < $count; $idx++) {
$item = $x->data->RSS[0]->CHANNEL[0]->ITEM[$idx];
echo "<div class=\"item\">\n";
echo "<a class=\"title\" href=\"" . $item->LINK[0]->_text . "\">" . $item->TITLE[0]->_text . "</a>\n";
echo "<div class=\"description\">" . $item->DESCRIPTION[0]->_text . "</div>\n";
echo "<div class=\"pubdate\">" . $item->PUBDATE[0]->_text . "</div>\n";
echo "</div>\n";
}
echo "</div>\n";
}