這樣做是相當的難!
簡單點吧!
PHP复制代码
<?php
$log_record = '2014-12-15 00:22:17 2932675381|0|任务信息获取成功|{"task_id":"22365","task_name":"\u7ad9\u957f\u5206\u4eab\u535a\u5ba2","user_id":"36723","target_host":"122.114.48.217","ftp_type":"1","ftp_port":"21","ftp_mode":"0","ftp_user":"administrator","ftp_passwd":"fasdode520","target_dir":null,"backup_dir":"\/youwujun","domain_name":"","freqence":"1","time_zone":null,"start_time":"2","back_time":"1402640307","last_backup_time":"1418573343","backup_count":"76","status_code":"0","cur_size":"8060713888","storeprovider":"99","flag":"5","extra_flag":"1","server_name":"NODE_ALIYUN_BJ_03","backup_node_name":null,"is_push":"0","is_ssl":"0","is_proxy":"0","pair_task_id":null,"create_time":"1402467444","update_time":"1418573343","ip_change_time":"1402467444","last_history_id":"990306","last_msg_type":"2","bus_type":"9","store_frequency":"2","sitestype":"2","sites_type":"1","ap_mp":"0","ext_info":null,"websize":"1","group_id":"33290","speed_level":"1","back_now":"0","open_web_scan":"0","history_max":"6"}|123.57.7.52';
$log_pattern = '/(.*?)\|(.*?)\|(.*?)\|(\{.*\})\|(.*)/';
$json_pattern = '/^\{.*\}$/';
if (preg_match($log_pattern, $log_record, $matches))
{
array_shift($matches);
foreach ($matches as $match)
{
if (preg_match($json_pattern, $match))
{
print_r(json_decode($match));
}
else
{
echo $match, "\n";
}
}
}
?>
复制代码
|