game/_incl_data/class/Core/ConversionHelper.php

26 lines
755 B
PHP
Raw Normal View History

<?php
namespace Core;
class ConversionHelper
{
/** <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> data ('a=1|b=2|c=3') <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [a=>1, b=>2, c=>3].
* @param string $dataString
* @return array
*/
public static function dataStringToArray(string $dataString): array
{
$arr = json_decode(str_replace(['=', '|'], ['":', ',"'], '{"' . $dataString . '}'), true);
return $arr ?: [];
}
/** <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [a=>1, b=>2, c=>3] <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> data ('a=1|b=2|c=3') <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>.
* @param array $dataArray
* @return string
*/
public static function arrayToDataString(array $dataArray): string
{
$str = json_encode($dataArray);
return $str ? str_replace(['":', ',"', '{"', '}'], ['=', '|'], $str) : '';
}
}