<?php
error_reporting(E_ALL);
$url = 'saved_report.xml';
define('XML_HEADER', '*RWRESPONSE*RESPONSE*DATA*HEADER*COLUMN');
define('XML_ROW', '*RWRESPONSE*RESPONSE*DATA*ROW*COLUMN');
$headers = array();
$rows = array();
function startTag($parser, $data) {
global $current_tag;
$current_tag .= "*$data";
}
function endTag($parser, $data) {
global $current_tag;
$tag_key = strrpos($current_tag, '*');
$current_tag = substr($current_tag, 0, $tag_key);
}
function contents($parser, $data) {
global $current_tag, $headers, $rows;
switch($current_tag) {
case XML_HEADER:
array_push($headers, $data);
break;
case XML_ROW:
array_push($rows, $data);
break;
}
}
// fetch the report
$curl_object = curl_init();
curl_setopt($curl_object, CURLOPT_URL, $url);
curl_setopt($curl_object, CURLOPT_HEADER, 0);
curl_setopt($curl_object, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_object, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl_object, CURLOPT_SSL_VERIFYHOST, 0);
$result = curl_exec($curl_object);
$error = curl_error($curl_object);
$info = curl_getinfo($curl_object);
curl_close($curl_object);
if ($error) {
die("An error occured while fetching the report\n");
}
// process the report
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "contents");
if(!(xml_parse($xml_parser, $result))){
die("Error on line " . xml_get_current_line_number($xml_parser));
}
xml_parser_free($xml_parser);
for($i = 0; $i \n";
}
echo ' ';
echo "$headers[3]: $rows[3] \n";
echo "$headers[4]: $rows[4] \n";
?>
运行此脚本时,我收到一个错误
“无法解析主机:saved_report.xml;没有请求类型的数据记录”
我无法解决这个问题 .
1 回答
您需要指定文件的完整路径,例如:
因为curl不适用于相对URL