Constants

ARRAY_FORMAT

ARRAY_FORMAT

Array output format

CSV_FORMAT

CSV_FORMAT

Comma Separated Value (CSV) output format

JSON_FORMAT

JSON_FORMAT

Json output format

HTML_FORMAT

HTML_FORMAT

HTML output format

PHP_FORMAT

PHP_FORMAT

PHP output format

SERIALIZED_FORMAT

SERIALIZED_FORMAT

Serialized output format

XML_FORMAT

XML_FORMAT

XML output format

DEFAULT_FORMAT

DEFAULT_FORMAT

Default format of this class

Properties

$_data

$_data : mixed

Data to parse

Type

mixed

$_from_type

$_from_type : string

Type to convert from

Type

string

$_CI

$_CI : object

CodeIgniter instance

Type

object

Methods

__construct()

__construct(NULL  $data = NULL, NULL  $from_type = NULL) 

DO NOT CALL THIS DIRECTLY, USE factory()

Parameters

NULL $data
NULL $from_type

Throws

\Exception

factory()

factory(mixed  $data, string  $from_type = NULL) : object

Create an instance of the format class e.g: echo $this->format->factory(['foo' => 'bar'])->to_csv();

Parameters

mixed $data

Data to convert/parse

string $from_type

Type to convert from e.g. json, csv, html

Returns

object —

Instance of the format class

to_array()

to_array(mixed|NULL  $data = NULL) : array

Format data as an array

Parameters

mixed|NULL $data

Optional data to pass, so as to override the data passed to the constructor

Returns

array —

Data parsed as an array; otherwise, an empty array

to_xml()

to_xml(mixed|NULL  $data = NULL, NULL  $structure = NULL, string  $basenode = 'xml') : mixed

Format data as XML

Parameters

mixed|NULL $data

Optional data to pass, so as to override the data passed to the constructor

NULL $structure
string $basenode

Returns

mixed

to_html()

to_html(mixed|NULL  $data = NULL) : mixed

Format data as HTML

Parameters

mixed|NULL $data

Optional data to pass, so as to override the data passed to the constructor

Returns

mixed

to_csv()

to_csv(mixed|NULL  $data = NULL, string  $delimiter = ',', string  $enclosure = '"') : string

Parameters

mixed|NULL $data

Optional data to pass, so as to override the data passed to the constructor

string $delimiter

The optional delimiter parameter sets the field delimiter (one character only). NULL will use the default value (,)

string $enclosure

The optional enclosure parameter sets the field enclosure (one character only). NULL will use the default value (")

Returns

string —

A csv string

to_json()

to_json(mixed|NULL  $data = NULL) : string

Encode data as json

Parameters

mixed|NULL $data

Optional data to pass, so as to override the data passed to the constructor

Returns

string —

Json representation of a value

to_serialized()

to_serialized(mixed|NULL  $data = NULL) : string

Encode data as a serialized array

Parameters

mixed|NULL $data

Optional data to pass, so as to override the data passed to the constructor

Returns

string —

Serialized data

to_php()

to_php(mixed|NULL  $data = NULL) : mixed

Format data using a PHP structure

Parameters

mixed|NULL $data

Optional data to pass, so as to override the data passed to the constructor

Returns

mixed —

String representation of a variable

_from_xml()

_from_xml(  $data) : \SimpleXMLElement

Parameters

$data

XML string

Returns

\SimpleXMLElement —

XML element object; otherwise, empty array

_from_csv()

_from_csv(string  $data, string  $delimiter = ',', string  $enclosure = '"') : array

Parameters

string $data

CSV string

string $delimiter

The optional delimiter parameter sets the field delimiter (one character only). NULL will use the default value (,)

string $enclosure

The optional enclosure parameter sets the field enclosure (one character only). NULL will use the default value (")

Returns

array —

A multi-dimensional array with the outer array being the number of rows and the inner arrays the individual fields

_from_json()

_from_json(  $data) : mixed

Parameters

$data

Encoded json string

Returns

mixed —

Decoded json string with leading and trailing whitespace removed

_from_serialize()

_from_serialize(  $data) : mixed

Parameters

$data

Returns

mixed —

Unserialized data

_from_php()

_from_php(  $data) : string

Parameters

$data

Data to trim leading and trailing whitespace

Returns

string —

Data with leading and trailing whitespace removed