我有名称为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列分隔为单独的列,并将其作为列发送到datatable
答案 0 :(得分:0)
如果我正确理解了您的问题,请尝试以下操作:
$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
中,您将拥有密钥对