function arr2ini(array $a, array $parent = array())
{
$out = '';
foreach ($a as $k => $v)
{
if (is_array($v))
{
//subsection case
//merge all the sections into one array...
$sec = array_merge((array) $parent, (array) $k);
//add section information to the output
$out .= '[' . join('.', $sec) . ']' . PHP_EOL;
//recursively traverse deeper
$out .= arr2ini($v, $sec);
}
else
{
//plain key->value case
$out .= "$k=$v" . PHP_EOL;
}
}
return $out;
}
$strings = file_get_contents(__DIR__ .'/logs/v.d');
$lb = [];
$line = preg_replace_callback(
'/([\x{4e00}-\x{9fa5}]+)/um',
function ($matches) use (&$lb) {
if (isset($matches[0])) {
$piy = \WiPortal\Helper\PinyinLib::topinyin($matches[0]);
$lb[ $piy ] = $matches[0];
return "%({$piy})%";
}
},
$strings
);
// \WiPortal\Helper\Debuger::dump($lb, $line);
highlight_string($line);
file_put_contents(__DIR__ .'/logs/v.x', $line);
$ini = arr2ini($lb);
file_put_contents(__DIR__ .'/logs/v.i', $ini);
\WiPortal\Helper\Debuger::dump($lb);
网友评论