php4中的xml解析
我知道这可能要求太多,但我一直在阅读有关xml解析的文章,我就是不明白!直到我完成编程(这是一个很好的经验教训),我才意识到我的客户机有php4,但我需要它在php4中工作:php4中的xml解析,php,xml,parsing,php4,Php,Xml,Parsing,Php4,我知道这可能要求太多,但我一直在阅读有关xml解析的文章,我就是不明白!直到我完成编程(这是一个很好的经验教训),我才意识到我的客户机有php4,但我需要它在php4中工作: $post_string= 'type=xml&cid=55505&minorRev=14&apiKey=4sr8d8bsn75tpcuja6ypx5g3&locale='.$userLocale.'¤cyCode='.$userCurr.'&customerIp
$post_string= 'type=xml&cid=55505&minorRev=14&apiKey=4sr8d8bsn75tpcuja6ypx5g3&locale='.$userLocale.'¤cyCode='.$userCurr.'&customerIpAddress='.$userIp.'&customerUserAgent='.$userAgent.'&xml=<HotelListRequest><destinationId>7EEF0188-E4DC-4B45-B4A7-57E3DF950E1F</destinationId><supplierCacheTolerance>MED_ENHANCED</supplierCacheTolerance><numberOfResults>200</numberOfResults></HotelListRequest>';
//Relative path to the file with $_POST parsing
$path = "http://api.ean.com/ean-services/rs/hotel/v3/list";
$ch = curl_init($path);
$fp = fopen('xml/data.xml','w');
//Send the data to the file
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/xml'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FILE, $fp);
$val = curl_exec($ch);
curl_close($ch);//Close curl session
fclose($fp); //Close file overwrite
$data = simplexml_load_file('xml/data.xml');
$post_string='type=xml&cid=55505&minorRev=14&apiKey=4sr8d8bsn75tpcuja6ypx5g3&locale='.$userLocale.¤cyCode='.$userCurr.&customerIpAddress='.$userIp.&customerUserAgent='.$userAgent.&xml=7EEF0188-E4DC-4B45-B4A7-57E3DF950E1FMED';
//解析后使用$\u的文件的相对路径
$path=”http://api.ean.com/ean-services/rs/hotel/v3/list";
$ch=curl\u init($path);
$fp=fopen('xml/data.xml','w');
//将数据发送到文件
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Accept:application/xml'));
curl_setopt($ch,CURLOPT_头,0);
curl_setopt($ch,CURLOPT_文件,$fp);
$val=curl_exec($ch);
卷曲关闭($ch)//闭卷会话
fclose($fp)//关闭文件覆盖
$data=simplexml_load_文件('xml/data.xml');
我简直被难住了。我只使用过这种格式来读取xml文档。有人能把它转换成php4吗??我再次知道这是一个很大的要求,但任何帮助都将非常感谢。提前谢谢。您应该向您的客户说明,从那时起,PHP4就没有任何支持了 也就是说,请阅读已经解决您的问题的问题 (参考答案)
如果你的客户真的想坚持使用不受支持的PHP版本(或者不能迁移到PHP5),那么他应该承担费用;维护遗留代码通常需要更多的努力。只是好奇而已。。为什么是PHP4???您的客户机应该真的,真的迁移到PHP5。PHP4不再被维护,甚至没有安全更新。如果是托管公司,他们拒绝更新,请离开。(有些情况下,由于旧软件的原因需要使用PHP4,但除非有完全紧迫的原因,否则使用PHP4在今天是不可能的。)真的吗?PHP4?这些天我不得不使用5.2,我会很难过。我建议您将您的客户指向此页面:。PHP4已经过时,而且不安全。但更重要的是,考虑到PHP4已经停产多久,运行PHP4的操作系统也可能存在危险的不安全性。你的客户正面临着被黑客入侵的严重风险,仅仅是通过在线使用这种系统。你的问题是,他们可能有自己的头在沙子里:通过承担项目,如果他们被黑客攻击,你很有可能会受到指责。我的建议是:逃跑我完全同意。。但他不想改变,他的托管公司也不会迁移。所以我别无选择。验收的可能副本表明这是重复的材料,也许很值得删除。
$xml = ...; // Get your XML data
$xml_parser = xml_parser_create();
// _start_element and _end_element are two functions that determine what
// to do when opening and closing tags are found
xml_set_element_handler($xml_parser, "_start_element", "_end_element");
// How to handle each char (stripping whitespace if needs be, etc
xml_set_character_data_handler($xml_parser, "_character_data");
xml_parse($xml_parser, $xml);