Format class

Help convert between various formats such as XML, JSON, CSV, etc.

package Fuel
category Core
author Fuel Development Team
copyright 2010 - 2012 Fuel Development Team
link http://docs.fuelphp.com/classes/format.html

 Methods

Do not use this directly, call forge()

__construct(mixed $data, string $from_type, mixed $param) 

Parameters

$data

mixed

general date to be converted

$from_type

string

data format the file was provided in

$param

mixed

additional parameter that can be passed on to a 'from' method

Exceptions

\FuelException

Loads Format config.

_init() 

Returns an instance of the Format object.

forge(mixed $data, string $from_type, mixed $param) : \Fuel\Core\Format

echo Format::forge(array('foo' => 'bar'))->to_xml();

Parameters

$data

mixed

general date to be converted

$from_type

string

data format the file was provided in

$param

mixed

additional parameter that can be passed on to a 'from' method

Returns

To array conversion

to_array(mixed $data) : array

Goes through the input and makes sure everything is either a scalar value or array

Parameters

$data

mixed

Returns

array

To CSV conversion

to_csv(mixed $data, mixed $delimiter, mixed $enclose_numbers, array $headings) : string

Parameters

$data

mixed

$delimiter

mixed

$enclose_numbers

mixed

$headings

array

Custom headings to use

Returns

string

To JSON conversion

to_json(mixed $data, bool $pretty) : string

Parameters

$data

mixed

$pretty

bool

whether to make the json pretty

Returns

string

To JSONP conversion

to_jsonp(mixed $data, bool $pretty, string $callback) : string

Parameters

$data

mixed

$pretty

bool

whether to make the json pretty

$callback

string

JSONP callback

Returns

stringformatted JSONP

Return as a string representing the PHP structure

to_php(mixed $data) : string

Parameters

$data

mixed

Returns

string

Serialize

to_serialized(mixed $data) : string

Parameters

$data

mixed

Returns

string

To XML conversion

to_xml(mixed $data, null $structure, null | string $basenode, null | bool $use_cdata, mixed $bool_representation) : string

Parameters

$data

mixed

$structure

null

$basenode

nullstring

$use_cdata

nullbool

whether to use CDATA in nodes

$bool_representation

mixed

if true, element values are true/false. if 1, 1/0.

Returns

string

Convert to YAML

to_yaml(mixed $data) : string

Parameters

$data

mixed

Returns

string

 Properties