Format クラス

The Format class helps you convert between various formats such as XML, JSON, CSV, etc.

forge($data = null, $from_type = null)

The forge method returns a new format object.

Static Yes
パラメータ
パラメータ 規定値 説明
$data
null
Data to be converted.
$from_type
null
Format of the data provided.
返り値 Fuel\Core\Format Object
$array = array('foo' => 'bar');
print_r(Format::forge($array));

// Returns
Fuel\Core\Format Object
(
	[_data:protected] => Array
	(
		[foo] => bar
	)
)
							

to_array($data = null)

The to_array method returns the given data as an array. Do not call this directly, use the forge method as described in the example.

Static No
パラメータ
パラメータ 規定値 説明
$data
null
Data to be converted.
返り値 array
$json_string = '{"foo":"bar","baz":"qux"}';
print_r(Format::forge($json_string, 'json')->to_array());

// Returns
Array
(
	[foo] => bar
	[baz] => qux
)
							

to_xml($data = null, $structure = null, $basenode = 'xml')

The to_xml method returns the given data as an XML string. Do not call this directly, use the forge method as described in the example.

Static No
パラメータ
パラメータ 規定値 説明
$data
null
Data to be converted.
$structure
null
Object of class SimpleXMLElement.
$basenode "xml" Basenode of XML markup.
返り値 string
$array = array('foo' => 'bar', 'baz' => 'qux');
print_r(Format::forge($array)->to_xml());

// Returns
// <?xml version="1.0" encoding="utf-8"?>
// <xml>
// 	<foo>bar</foo>
// 	<baz>qux</baz>
// </xml>
							

to_csv($data = null, $separator = ',')

The to_csv method returns the given data as a CSV string. Do not call this directly, use the forge method as described in the example.

Static No
パラメータ
パラメータ 規定値 説明
$data
null
Data to be converted.
$separator
','
CSV field separator. Defaults to a comma.
返り値 string
$json_string = '{"foo":"bar","baz":"qux"}';
print_r(Format::forge($json_string, 'json')->to_csv());

// Returns
// foo,baz
// "bar","qux"
							

to_json()

The to_json method returns the given data as a JSON string. Do not call this directly, use the forge method as described in the example.

Static No
返り値 string
$array = array('foo' => 'bar', 'baz' => 'qux');
print_r(Format::forge($array)->to_json());

// Returns
// {"foo":"bar","baz":"qux"}
							

to_serialized()

The to_serialized method returns the given data as a serialized string. Do not call this directly, use the forge method as described in the example.

Static No
返り値 string
$array = array('foo' => 'bar', 'baz' => 'qux');
print_r(Format::forge($array)->to_serialized());

// Returns
// a:2:{s:3:"foo";s:3:"bar";s:3:"baz";s:3:"qux";}
							

to_php()

The to_php method returns the given data as a PHP representation of the data in a string. You could pass this into eval() or use it for other crazy things.

Static No
返り値 string
$array = array(1, 2, array('a', 'b', 'c'));
print_r(Format::forge($array)->to_php());

// Returns
Array
(
	0 => 1,
	1 => 2,
	2 => array(
		0 => 'a',
		1 => 'b',
		2 => 'c',
	),
)