【发布时间】:2015-06-02 19:21:05
【问题描述】:
我的数据 -
{'/Users/aaron/Applications/developer-vagrant/web/g.php': {'total': 22}}
{'/Users/aaron/.vim/autoload/timetap.vim': {'total': 0}}
{'/Users/aaron/.vimrc': {'total': 5}}
{'/Users/aaron/Documents/Programming/PHP/TimeTapCLI/composer.json': {'total': 144}}
{'/Users/aaron/Documents/Programming/PHP/TimeTapCLI/timetap.php': {'total': 351}}
{'/Users/aaron/Box/linux/.vim/autoload/timetap.vim': {'total': 37}}
{'/Users/aaron/Box/cats.tex': {'total': 184}}
我正在尝试创建一个正则表达式,以便可以使用 preg_match 将上述内容转换为数组。我希望数据看起来像 -
我想要一个包含所有数据的数组所以我相信它应该如下所示-
array (
[0] => array (
[0] => '/Users/aaron/Box/cats.tex'
[1] => array (
[total] =>'184'
)
}
}
我对 preg_match 的尝试 -
$subject = file_get_contents('/Users/aaron/.timetap/full.db');
$pattern = '{...}';
preg_match($pattern, substr($subject,3), $matches, PREG_OFFSET_CAPTURE);
为了获取上述数据并将其转换为 PHP 中的数组,模式是什么?是否有一个 PHP 函数可以在不使用 preg_match 的情况下将其转换为数组?
【问题讨论】:
标签: php arrays regex preg-match