note 117774 added to function.yaml-parse-file
| From: | ArneL. | Date: | Fri, 07 Aug 2015 09:34:14 +0000 |
| Subject: | note 117774 added to function.yaml-parse-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203280@lists.php.net to get a copy of this message | ||
As Jesse Donat mentioned the type will be infered automatically. To enforce some type you can use
the callback facility like this:
<?php
function cb_yaml_date($value, $tag, $flags) {
return new DateTime($value);
}
$yaml = <<<YAML
event1:
name: My Event
date: !date 25.05.2001
YAML;
$ndocs = 0;
$data = yaml_parse($yaml, 0, $ndocs, array('!date' => 'cb_yaml_date'));
print_r($data);
?>
The above example will output something similar to:
Array
(
[event1] => Array
(
[name] => My Event
[date] => DateTime Object
(
[date] => 2001-05-25 00:00:00
[timezone_type] => 3
[timezone] => Europe/Berlin
)
)
)
BTW if you want to have large numbers you are probably using BC Math. Thus, you simple enclose your
number in quotes:
<?php
$yaml = <<<YAML
largenumber: '14695760472279668267313200104308'
YAML;
?>
----
Server IP: 72.52.91.14
Probable Submitter: 178.0.251.90
----
Manual Page -- http://php.net/manual/en/function.yaml-parse-file.php
Edit -- https://master.php.net/note/edit/117774
Del: integrated -- https://master.php.net/note/delete/117774/integrated
Del: useless -- https://master.php.net/note/delete/117774/useless
Del: bad code -- https://master.php.net/note/delete/117774/bad+code
Del: spam -- https://master.php.net/note/delete/117774/spam
Del: non-english -- https://master.php.net/note/delete/117774/non-english
Del: in docs -- https://master.php.net/note/delete/117774/in+docs
Del: other reasons-- https://master.php.net/note/delete/117774
Reject -- https://master.php.net/note/reject/117774
Search -- https://master.php.net/manage/user-notes.php