$preg = '/USER\-[0-9]+\-[A-Z]{1}/';
$result = \str_replace(['\\', '/'], '', $preg);
\preg_match_all('/\[([\w\d-]+)\][{]*([\+\*\d,]+)[}]*/', $preg, $match);
$maxCount = 10;
if (!empty($match[0])) {
foreach ($match[1] as $key => $part) {
$part = \explode('-', $part);
$range = \range($part[0], $part[1]);
$countData = $match[2][$key];
if ($countData == '+') {
$count = \mt_rand(1, $maxCount);
} elseif ($countData == '*') {
$count = \mt_rand(0, $maxCount);
} else {
$countData = \explode(',', $countData);
if (isset($countData[1])) {
$count = \mt_rand($countData[0], $countData[1]);
} else {
$count = $countData[0];
}
}
$n = 0;
$generated = '';
$rangeTotal = \sizeof($range);
for ($n; $n < $count; ++$n) {
$randKey = \mt_rand (0, $rangeTotal - 1);
$generated .= $range[$randKey];
}
$replace = $match[0][$key];
$result = \str_replace($replace, $generated, $result);
}
}
echo $result;
$time = \strtotime('2017-01-01');
$day = \date('l', $time);
echo $day;
\date_default_timezone_set('Europe/Moscow');
$json = '{
"meta": {
"p": 273876598,
"a": 370637443,
"t": "Сообшение 1",
"d": 1485679498
},
"data": [
{
"i": 56645,
"f": 370637443,
"t": "Сообшение 2",
"d": 346934331
},
{
"i": 56644,
"f": 370637443,
"t": "Сообшение 3",
"d": 346934327
}
]
}';
$arr = \json_decode($json, true);
$html = '';
foreach ($arr as $key => $val) {
if (isset($val['t']) && isset($val['d'])) {
$date = \date('d.m.y H:i', $val['d']);
$html .= "<p>{$val['t']}<br>$date</p>";
} else {
foreach ($val as $key2 => $val2) {
if (isset($val2['t']) && isset($val2['d'])) {
$date = \date('d.m.y H:i', $val2['t']);
$html .= "<p>{$val2['t']}<br>$date</p>";
}
}
}
}
echo $html;