Json美化输出
if (!function_exists('p')) {
// 传递数据以易于阅读的样式格式化后输出
function p($data)
{
// $array = [];
// // 定义样式
// echo '<pre style="display: block;padding: 9.5px;margin: 44px 0 0 0;font-size: 17px;line-height: 1.42857;color: #333;word-break: break-all;word-wrap: break-word;background-color: #F5F5F5;border: 1px solid #CCC;border-radius: 4px;">';
// foreach ($data as $key => $value) {
//// $array[$key] = json_decode(json_encode($value), true);
// echo '<div class="bs">';
// $array[$key] = $value;
// echo '</div>';
// }
//
// echo '<div id="test">';
// print_r($array);
// echo '</div>';
// echo '</pre>';
// 字段置顶
$top_infos = [];
foreach ($data as $kk => $vv) {
if ($kk == 'startTime') {
$top_infos['startTime'] = $vv;
unset($data[$kk]);
}
}
$data = array_merge($top_infos, $data);
echo '<div style="padding:0px 32px;white-space: pre-line;word-wrap:break-word;display: block;margin: 44px 0 0 0;font-size: 17px;line-height: 1.42857;color: #333;word-break: break-all;word-wrap: break-word;background-color: #F5F5F5;border: 1px solid #CCC;border-radius: 4px;">
<span ><i style="cursor:pointer;" onclick="hide(this)"></i>{';
foreach ($data as $key => $value) {
if (end($data) == $value) {
echo "<br> <span contenteditable=\"true\" style='color: #92278f;font-weight: bold;'>\"{$key}\"</span>:<span contenteditable=\"true\" style='color: #3ab54a;font-weight: bold;'>\"$value\"</span>";
}else{
echo "<br> <span contenteditable=\"true\" style='color: #92278f;font-weight: bold;'>\"{$key}\"</span>:<span contenteditable=\"true\" style='color: #3ab54a;font-weight: bold;'>\"$value\"</span>,";
}
}
echo '<br>}</span>';
echo '</div>';
}
}
本作品采用《CC 协议》,转载必须注明作者和本文链接
3v4l.org/69INA