相关疑难解决方法(0)

使用SimpleXML不再存在节点

尝试使用名为get_transient的wordpress函数构建来缓存xml文件,但是我收到了一个php错误:

unserialize()[function.unserialize]:节点不再存在

//check the db to see if it exists ( get_transient is a WordPress function)
if (false === ($response_xml = get_transient('stats_from_xml_feed'))){

 $request_url = "http://example.com/feed.xml";
 $request_url = urlencode($request_url);
 $response_xml = @simplexml_load_file($request_url);
 //kill request if connection problem
 if ($response_xml === FALSE){
 exit ('could not connect');
 } else {
     // here we throw it into the WordPress temp DB using set_transient for 12 hours
   set_transient('stats_from_xml_feed', $response_xml, 60*60*12);

 //some output
$res =  $response_xml;
$name = $res->name;

echo $name;
}
Run Code Online (Sandbox Code Playgroud)

php simplexml

2
推荐指数
1
解决办法
3957
查看次数

标签 统计

php ×1

simplexml ×1