-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfdi_reader.php
46 lines (36 loc) · 1.04 KB
/
cfdi_reader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
function cfdi_reader($xml_data){
$xml = new SimpleXMLElement($xml_data);
// if is a CFDI
echo 'validating';
if(array_key_exists("cfdi",$xml->getNamespaces())){
print_r(
// Array(
// $xml->children()
// )
//$xml->children("cfdi",true)->Conceptos
$xml->attributes()->fecha
);
$date = (string)$xml->attributes()->fecha;
$children = $xml->children("cfdi",true);
print_r($children->Emisor->attributes()->nombre);
foreach ($children->Conceptos->children("cfdi",true) as $value) {
$values = $value->attributes();
$data = array(
"code" => (string)$values->noIdentificacion,
"concept" => (string)$values->descripcion,
"amount" => (string)$values->importe,
"source" => "CFDI ".$children->Emisor->attributes()->nombre,
"date" => $date
);
print_r($data);
# code...
}
}
}
#test
$xml = file_get_contents("SECFD_20150603_040627.xml");
cfdi_reader($xml);
echo "fin";