Php how to represent a multi-level array in string form

This is an example of a mixed tiered irregular array in php:

$settings['style_formats'] = array(
  array('title' => 'Center table', 'selector' => 'table', 'styles' => array('margin-left' => 'auto', 'margin-right' => 'auto')),
  array('title' => 'Menu style', 'selector' => 'ul,ol', 'classes' => 'menu'),
  array('title' => 'Layer2', 'inline' => 'div', 'styles' => array('background-color' => 'orange')),
  array('title' => 'Bold text', 'inline' => 'b'),
  array('title' => 'Red text', 'inline' => 'span', 'styles' => array('color' => '#ff0000')),
  array('title' => 'Red header', 'block' => 'h1', 'styles' => array('color' => '#ff0000')),
  array('title' => 'Example 1', 'inline' => 'span', 'classes' => 'example1'),
  array('title' => 'Example 2', 'inline' => 'span', 'classes' => 'example2'),
  array('title' => 'Table styles'),
  array('title' => 'Table row 1', 'selector' => 'tr', 'classes' => 'tablerow1'),
);

I need to find a method for representing and translating such an array from string format to php array. The format of the source string must be accessible for reading and writing by a person using a text editor. So, for example, this should not be the result of using "serialize", because "serialize" is a php function (and, rather, it is impossible for humans to create), and the string must be available for manual creation in a text editor.

The string will be passed as a parameter to a function that will translate it into a php array, such as above.

, - "". , "" , . preg_split , .

, ?

+3
3

JSON - : ( )

{"style_formats":[{"title":"Center table","selector":"table","styles":{"margin-left":"auto","margin-right":"auto"}},{"title":"Menu style","selector":"ul,ol","classes":"menu"},{"title":"Layer2","inline":"div","styles":{"background-color":"orange"}},{"title":"Bold text","inline":"b"},{"title":"Red text","inline":"span","styles":{"color":"#ff0000"}},{"title":"Red header","block":"h1","styles":{"color":"#ff0000"}},{"title":"Example 1","inline":"span","classes":"example1"},{"title":"Example 2","inline":"span","classes":"example2"},{"title":"Table styles"},{"title":"Table row 1","selector":"tr","classes":"tablerow1"}]}
+1

, YAML .

PHP.

+1
source

All Articles