api_helpers.php
API helper functions
Zed. The immensity of stars. The HyperShip. The people.
(c) 2010, Dereckson, some rights reserved. Released under BSD license.
This file provides a functions to output the API message in several formats.
The supported formats are preview (PHP dump), XML, PHP serialize and json.
The XML outputs code uses the following codes: - http://www.thedeveloperday.com/xml-beautifier-tool/ - http://snipplr.com/view/3491/convert-php-array-to-xml-or-simple-xml-object-if-you-wish/
Tags
Table of Contents
Functions
- toXml() : string
- The main function for converting to an XML document.
- api_output() : mixed
- Outputs API reply, printing it in the specified format.
Functions
toXml()
The main function for converting to an XML document.
toXml(mixed $data[, string $rootNodeName = 'data' ][, SimpleXMLElement $xml = null ][, string $unknownNodeName = 'unknownNode' ]) : string
Pass in a multidimensional array and this recursively loops through and builds up an XML document.
Parameters
- $data : mixed
- $rootNodeName : string = 'data'
-
What you want the root node to be — defaults to data.
- $xml : SimpleXMLElement = null
-
Should only be used recursively
- $unknownNodeName : string = 'unknownNode'
-
Name to give to unknown (numeric) keys
Return values
string —XML
api_output()
Outputs API reply, printing it in the specified format.
api_output(mixed $reply, string $xmlRoot[, string $xmlChildren = "item" ]) : mixed
The format will be read form $_REQUEST['format'].
Parameters
- $reply : mixed
-
the reply to format
- $xmlRoot : string
-
the XML root element name (optional, default value is 'data').
- $xmlChildren : string = "item"
-
the XML children elements name (optional, will be deducted from the context if omitted, or, if not possible, will be unknownNode)