【问题标题】:xml parsing in php4php4中的xml解析
【发布时间】:2012-10-13 18:17:42
【问题描述】:

我知道这可能问得太多了,但是我一直在阅读有关 xml 解析的内容,但我就是不明白!在我完成编程之前我没有意识到我的客户有 PHP 4(一个很好的教训),但我需要它在 php4 中工作:

$post_string= 'type=xml&cid=55505&minorRev=14&apiKey=4sr8d8bsn75tpcuja6ypx5g3&locale='.$userLocale.'&currencyCode='.$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');

我简直被难住了。我只使用过这种格式来读取 xml 文档。任何人都可以将其转换为在 php4 上工作吗?我再次知道这是很多问题,但任何帮助都会非常感激。提前谢谢你。

【问题讨论】:

  • 只是好奇.. 为什么 PHP 4 ???
  • 您的客户端真的应该迁移到 PHP 5。PHP 4 不再得到维护,甚至没有安全更新。如果是托管公司,并且他们拒绝更新,请离开。 (在某些情况下,由于旧软件需要 PHP 4,但除非有完全紧迫的原因,否则今天使用 PHP 4 是不行的。)
  • 认真的吗? PHP4?这些天我不得不使用 5.2 工作,我会很沮丧。我建议您将您的客户指向此页面:php.net/releases/index.php。 PHP4 已经过时并且非常不安全。但更重要的是,考虑到它已经停产了多长时间,运行 PHP4 的操作系统也可能存在危险的不安全性。仅通过在线使用这种系统,您的客户就有被黑客入侵的严重风险。你的问题是他们可能一头雾水:通过承担这个项目,如果他们被黑客入侵,你很有可能会受到指责。我的建议:逃跑
  • 我完全同意.. 但他不想改变,他的托管公司也不会迁移。所以我别无选择。

标签: php xml parsing php4


【解决方案1】:

您应该向您的客户说明,自 August 8th, 2008!

以来,PHP 4根本没有任何支持

也就是说,请阅读 this 问题,该问题已经解决了您的问题。

(来自参考答案)

$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);

如果您的客户真的想要坚持使用不受支持的 PHP 版本(或者无法迁移到 PHP 5),那么 应该为此承担费用;维护遗留代码通常需要更多的努力。

【讨论】:

  • 验收表明这是重复的材料,也许值得删除。
猜你喜欢
  • 2014-11-26
  • 2010-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-01
  • 2021-06-29
  • 1970-01-01
相关资源
最近更新 更多