Skip to content

PeterNotenboom/EppXml-2-Array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EppXml-2-Array v1.4

An EPP (http://en.wikipedia.org/wiki/Extensible_Provisioning_Protocol), with Namespace support, to a simple Array. Still usable for normal XML too. CDATA is supported.

Why not use xyz?

For regular XML you can use this (probably) fine:

$xml = simplexml_load_string($xmlstring);
$json = json_encode($xml);
$array = json_decode($json,TRUE);

But it doesn't work "out of the box" with namespaces. Also, simplexml_load_string somehow removes certain attributes. For example, if your EPP had:

<domain:contact type="billing">P-ABC120</domain:contact>

It will remove the "type" attribute. And for EPP any missing information makes those methods unusable.

How to use

First, load the XML:

PN\Xml2Array::loadXML($xml_string);
//or
PN\Xml2Array::loadXML(file_get_contents('somefile.xml'));

Get the whole array from your complete EPP string:

print_r( PN\Xml2Array::getArray() );

Get all the Namespace prefixes + URI's as an array:

print_r( PN\Xml2Array::getNamespaces() );

Get a part of the EPP in array by giving the prefix:

print_r( PN\Xml2Array::getArrayNS('contact') );
Added in v1.1

Too lazy to look where in the array/xml a tag is? Or the tag could be changing in different xml files? See example1.php, use it like this:

print_r( PN\Xml2Array::getArrayElement('domain', 'pw', true ) );
Added in v1.3

Want to get an attribute like:

<result code="1000">...

See example1.php, use it like this:

print_r( Xml2Array::getArrayAttribute(null, 'result', 'code', true) );

Simple as that.

License

MIT

About

XML/EPP to a simple readable array, including Namespace and CDATA support

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages