Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从https URL获取XML_Php_Xml_Https_Parsing - Fatal编程技术网

Php 从https URL获取XML

Php 从https URL获取XML,php,xml,https,parsing,Php,Xml,Https,Parsing,我试图从多个XML提要获取数据,并将这些数据复制到本地数据库。我试着研究SimpleXML和我在互联网上发现的一些其他东西,但我想知道使用这种东西的最佳途径是什么 我正在寻找一种不仅可以从安全位置获取XML,还可以将其转换为一系列数组的东西。当使用获取XML作为包含节点数组的对象时。我个人更喜欢使用SimpleXML而不是任何其他XML解析器,因为它的简单性和总体性能。在处理数据时,它很容易用作DOM操纵器,在用作XPath解析器时,也很容易仅检索几个节点 如果要遍历一个非常大的XML文件,最好

我试图从多个XML提要获取数据,并将这些数据复制到本地数据库。我试着研究SimpleXML和我在互联网上发现的一些其他东西,但我想知道使用这种东西的最佳途径是什么

我正在寻找一种不仅可以从安全位置获取XML,还可以将其转换为一系列数组的东西。

当使用获取XML作为包含节点数组的对象时。我个人更喜欢使用SimpleXML而不是任何其他XML解析器,因为它的简单性和总体性能。在处理数据时,它很容易用作DOM操纵器,在用作XPath解析器时,也很容易仅检索几个节点

如果要遍历一个非常大的XML文件,最好使用一个直接加载惰性的SAX解析器,但由于您是通过网络进行读取的,因此我认为性能差异是可以忽略的。

使用XML时,您将XML作为包含节点数组的对象。我个人更喜欢使用SimpleXML而不是任何其他XML解析器,因为它的简单性和总体性能。在处理数据时,它很容易用作DOM操纵器,在用作XPath解析器时,也很容易仅检索几个节点


如果要遍历一个非常大的XML文件,最好使用一个直接加载惰性的SAX解析器,但由于您是通过网络读取的,因此我相信性能差异是可以忽略的。

这是一个非常简单的过程,您可以使用CURL和某种排序的XML-to-array类来完成。我将在这里向您详细介绍这两个方面

PHP:

/* run mozilla agent */
$agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1';

$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $agent); //make it act decent
curl_setopt($ch, CURLOPT_URL, $url);         //set the $url to where your request goes
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //set this flag for results to the variable
curl_setopt($ch, CURLOPT_POST, 1);           //if you're making a post, put the data here
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); //as a key/value pair in $post
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //This is required for HTTPS certs if
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //you don't have some key/password action

/* execute the request */
$result = curl_exec($ch);
curl_close($ch);

/* now parse the resulting XML using XMLToArray class from 
Razzaque Rupom http://groups.yahoo.com/group/phpresource/ */
require_once('lib/class.XmlToArray.php');
$parser = new XmlToArray($result);
$data = $parser->createArray();
就在这里

  • 米奇

这是一个非常简单的过程,您可以使用CURL和一些排序XML-to-array类来完成。我将在这里向您详细介绍这两个方面

PHP:

/* run mozilla agent */
$agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1';

$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $agent); //make it act decent
curl_setopt($ch, CURLOPT_URL, $url);         //set the $url to where your request goes
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //set this flag for results to the variable
curl_setopt($ch, CURLOPT_POST, 1);           //if you're making a post, put the data here
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); //as a key/value pair in $post
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //This is required for HTTPS certs if
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //you don't have some key/password action

/* execute the request */
$result = curl_exec($ch);
curl_close($ch);

/* now parse the resulting XML using XMLToArray class from 
Razzaque Rupom http://groups.yahoo.com/group/phpresource/ */
require_once('lib/class.XmlToArray.php');
$parser = new XmlToArray($result);
$data = $parser->createArray();
就在这里

  • 米奇

使用cURL()从https位置获取数据,然后使用simplexml\u load\u字符串加载数据。

使用cURL()从https位置获取数据,然后使用simplexml\u load\u字符串加载数据。

您可以找到他在这里引用的xmltarray类:您可以找到他在这里引用的xmltarray类: