Node no longer exists using SimpleXML(使用SimpleXML的节点不再存在)
                            本文介绍了使用SimpleXML的节点不再存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
                        
                        问题描述
尝试使用名为Get_Temporent的内置WordPress函数缓存XML文件,但收到php错误:
unSerialize()[unction.unSeries]:节点不再存在
//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;
}
推荐答案
您的$response_xml是SimpleXMLElement类的实例。SimpleXMLElement不应(取消)序列化,因为它将resource包装在对象中。
相反,序列化一些可以顺利通过该过程的内容;来自提要的原始响应、将其加载到SimpleXMLElement并使用asXML()方法、所需(可能是字符串)值的数组或其他可以序列化的结构后的全部/部分XML。
需要考虑的一件事是,您将在"较旧"的PHP版本中看到unserialize(): Node no longer exists警告。从PHP 5.3.2开始,行为更改为抛出Exception并显示消息Serialization of 'SimpleXMLElement' is not allowed。
这篇关于使用SimpleXML的节点不再存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
				 沃梦达教程
				
			本文标题为:使用SimpleXML的节点不再存在
				
        
 
            
        基础教程推荐
             猜你喜欢
        
	     - 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
 - PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
 - php中的PDF导出 2022-01-01
 - Yii2 - 在运行时设置邮件传输参数 2022-01-01
 - 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
 - php 7.4 在写入变量中的 Twig 问题 2022-01-01
 - php中的foreach复选框POST 2021-01-01
 - Web 服务器如何处理请求? 2021-01-01
 - 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
 - 将变量从树枝传递给 js 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				