T
T
truekenny2015-08-08 02:13:36
PHP
truekenny, 2015-08-08 02:13:36

Yaml/php how to parse correctly?

<?
var_dump(yaml_parse('foo: [b]'));
var_dump(yaml_parse('foo: [n]'));
var_dump(yaml_parse('foo: [y]'));

array(1) {
  ["foo"]=>
  array(1) {
    [0]=>
    string(1) "b"
  }
}
array(1) {
  ["foo"]=>
  array(1) {
    [0]=>
    bool(false)
  }
}
array(1) {
  ["foo"]=>
  array(1) {
    [0]=>
    bool(true)
  }
}

I expect n/y instead of false/true . How to achieve this?
Module Version	1.2.0
LibYAML Version	0.1.6

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Chizhik, 2015-08-20
@kzooz

If you do not change the incoming yaml - then nothing. Y/N are key characters and are interpreted as booleans according to the specification . If you need to get a symbolic representation, enclose them in quotes:

var_dump(yaml_parse("foo: ['y']"));
array(1) {
  ["foo"]=>
  array(1) {
    [0]=>
    string(1) "y"
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question