Php 如何解析数组数据?
我正在尝试使用foreach解析以下数组数据。但是我不能让它工作。如何从以下数组数据解析消息和xmlpath信息 下面是使这个问题更具信息性的完整代码。我正在尝试使用XmlValidator验证XML和XSD模式。目标是解析验证信息,以便我能够控制验证生成的信息Php 如何解析数组数据?,php,arrays,parsing,Php,Arrays,Parsing,我正在尝试使用foreach解析以下数组数据。但是我不能让它工作。如何从以下数组数据解析消息和xmlpath信息 下面是使这个问题更具信息性的完整代码。我正在尝试使用XmlValidator验证XML和XSD模式。目标是解析验证信息,以便我能够控制验证生成的信息 $xml = note.xml; $schema = note.xsd; $ds = DIRECTORY_SEPARATOR; require_once(dirname(__FILE__).$ds.'XMLValidator.php'
$xml = note.xml;
$schema = note.xsd;
$ds = DIRECTORY_SEPARATOR;
require_once(dirname(__FILE__).$ds.'XMLValidator.php');
$validator = new XMLValidator();
$result = $validator->validateXML($xml, $schema);
$result['time'] = date("Y-m-d H:i:s");
// Here is the print_r of the $result:
echo '<pre>'; print_r($result); echo '<pre/>';
Array
(
[success] =>
[messages] => Array
(
)
[errors] => Array
(
[0] => LibXMLError Object
(
[level] => 1
[code] => 1549
[column] => 0
[message] => failed to load external entity "/var/www/html/pdf/notexml"
[file] =>
[line] => 0
)
)
[xmlPath] => notexml
[mainSchemaPath] => notexsd
[time] => 2015-04-27 23:22:29
)
$xml=note.xml;
$schema=note.xsd;
$ds=目录\分隔符;
require_once(dirname(__文件).$ds.xmlvalidater.php');
$validator=新的XMLValidator();
$result=$validator->validateXML($xml,$schema);
$result['time']=日期(“Y-m-d H:i:s”);
//以下是$result的打印结果:
回声';打印(结果);回声';
大堆
(
[成功]=>
[消息]=>数组
(
)
[错误]=>数组
(
[0]=>LibXMLError对象
(
[级别]=>1
[代码]=>1549
[列]=>0
[消息]=>加载外部实体失败“/var/www/html/pdf/notexml”
[文件]=>
[行]=>0
)
)
[xmlPath]=>notexml
[mainSchemaPath]=>notexsd
[时间]=>2015-04-27 23:22:29
)
查看PHP foreach函数。您可以这样做:
解析的预期结果是什么?请编辑您的问题,以包含您当前用于尝试此操作的PHP代码。即使它不起作用,它也会让人们从一开始就了解它不起作用的原因。foreach($result as$arr){echo$xmlpath=$arr['xmlpath'];}尝试过,但出于某种原因,当我期望值为:notexml时,echo给了我:nn2的值
foreach($array as $arr){
$xmlpath = $arr['xmlPath'];
}