gpt4 book ai didi

php - 使用 laravel mysql 将列的数据转换为多列(将列的数据转换为特定列)

转载 作者:行者123 更新时间:2023-11-29 15:26:15 24 4
gpt4 key购买 nike

我的数据库的列名称是 msg ,该列将保存这样的日志数据

time=13:43:17 devname="IYC-KIZ-YURDU" devid="FG100D3G12811704" logid="0000000013" type="traffic" subtype="forward" level="notice" vd="root" eventtime=1569408197 srcip=172.16.3.166 srcname="android-44713cd294193fd7" srcport=40583 srcintf="lan" srcintfrole="lan" dstip=40.90.137.125 dstport=443 dstintf="wan1" dstintfrole="wan" poluuid="f8fea7d4-f01a-51e8-6ad6-ed9b47f5b56c" sessionid=1226038 proto=6 action="server-rst" user="30853744318" group="Radius" authserver="DC_Radius" policyid=13 policytype="policy" service="HTTPS" dstcountry="United States" srccountry="Reserved" trandisp="snat" transip=192.168.100.32 transport=40583 appid=41475 app="Microsoft.Authentication" appcat="Collaboration" apprisk="elevated" applist="iyc_app" duration=246 sentbyte=2203 rcvdbyte=7189 sentpkt=19 rcvdpkt=19 wanin=6217 wanout=1207 lanin=1207 lanout=1207 utmaction="allow" countapp=1 sentdelta=0 rcvddelta=132 devtype="Android Phone" devcategory="Android Device" osname="Samsung Galaxy" osversion="Android 5.1.1" mastersrcmac="e4:5d:75:c4:d5:5b" srcmac="e4:5d:75:c4:d5:5b" srcserver=0 |       NULL |       NULL | NULL        | NULL      |          NULL |    NULL | NULL         

所以我想做的是将这一列拆分为多列,空白在两列之间分隔,这是我从数据库获取数据的代码

$draw = intval($request->input('draw'));
$start = intval($request->input('start'));
$length = intval($request->input('length'));
$order = $request->input('order');
$search=$request->input('search');
$search = $search['value'];
$col = 0;
$dir = "";
$limit = (int)$request->input('length');
$total_logs= $this->totalLogs();
$offset=$draw * $length;
$data=Logs::offset($offset)->limit($limit)->get();// DataTables::of(Logs::take($limit )->get(['msg', 'sys']))->make(true);

$output = array(
"draw" => $draw,
"recordsTotal" => $total_logs,
"recordsFiltered" => $total_logs,
"data" => $data
);

echo json_encode($output);

此代码用于服务器端数据表,但我想要的是将 msg 列分成单独的列并将其作为列发送到数据表

最佳答案

如果我正确理解你的问题,请尝试以下操作:

$pairs = explode(' ', $s); // explode by space
$res = []; // here will be results
foreach ($pairs as $pair) { // traverse all pairs
$trimmed = trim($pair); // trim spaces
if ( !$trimmed || 'NULL' === $trimmed || '|' === $trimmed ) {
continue; // skip garbage
}
$data = explode('=', $pair); // split by '='
$res[$data[0]] = isset($data[1]) ? str_replace('"', '', $data[1]) : ''; // put into result
}

然后在$res中你就有了 key 对

关于php - 使用 laravel mysql 将列的数据转换为多列(将列的数据转换为特定列),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59071437/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com