Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从文本日志文件通知中提取数据_Php - Fatal编程技术网

Php 从文本日志文件通知中提取数据

Php 从文本日志文件通知中提取数据,php,Php,我想就这项任务的最佳方法提出建议 我有一个保存gps数据的文本日志文件,格式如下: time,lat,lon,elevation,accuracy,bearing,speed 2014-07-08T12:56:52Z,56.187344,10.192660,116.400024,5.000000,285.000000,1.063350 2014-07-08T12:56:58Z,56.187299,10.192754,113.799988,5.000000,161.000000,3.75300

我想就这项任务的最佳方法提出建议

我有一个保存gps数据的文本日志文件,格式如下:

time,lat,lon,elevation,accuracy,bearing,speed

2014-07-08T12:56:52Z,56.187344,10.192660,116.400024,5.000000,285.000000,1.063350

2014-07-08T12:56:58Z,56.187299,10.192754,113.799988,5.000000,161.000000,3.753000

2014-07-08T12:57:07Z,56.186922,10.193048,129.200012,5.000000,159.000000,5.254200

2014-07-08T12:57:13Z,56.186694,10.193133,109.799988,5.000000,152.000000,3.878100

2014-07-08T12:57:16Z,56.186745,10.193304,142.900024,5.000000,149.000000,3.940650

2014-07-08T12:57:20Z,56.186448,10.193417,118.700012,5.000000,154.000000,2.376900

2014-07-08T12:57:27Z,56.186492,10.193820,131.299988,5.000000,65.000000,5.379300
我需要找到速度超过某个值的行,然后从该行获取时间,然后滚动各行,找到速度低于该值的行,获取时间并将这两个时间值写入我的数据库

这必须是一个自动化的任务,所以我假设cronphp脚本可以完成这项工作


向托马斯致以最诚挚的问候

尽管不需要特别的建议,但我希望有人能为你的问题编写代码,我会尽力为你指明正确的方向。我已经编写了易于理解的代码,您可以在此基础上构建(未经测试)


您是在寻求建议还是找人帮您解决问题?你必须向我们表明,你已经为自己解决这个问题付出了一些努力。我将尝试自己解决这个问题,只是需要关于最佳方法的建议。我只是想具体说明一下这个任务。非常感谢,但我只是想征求意见,看看使用PHP是否是个坏主意。托马斯韦尔。。。我没有在问题中找到那句话——你只是问她是不是一个好主意。无忧:很难说。使用php是可能的,但可能有更好的选择。这取决于你计划的进口数量。最好使用像C/C++这样的低级语言。
<?php
// Setup.
$pathGpsFile = 'gps.log';
$speedThreshold = 5;

//
// Execution.
//
if(!file_exists($pathGpsFile)) {
    die('File "'. $pathGpsFile .'" does not exist.');
}

// Read entries into array.
$gpsEntries = file($pathGpsFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

// Loop through entries.
$lineCount = 0;
$currentDifferences = array();
$currentDifference = array();

foreach($gpsEntries as $gpsEntry) {
    // Skip head.
    if($lineCount == 0) {
        $lineCount++;
        continue;
    }

    // Extract values from gps entry.
    list($time, $lat, $lon, $elevation, $accuracy, $bearing, $speed) = explode(',', $gpsEntry);

    // Check if there is currently a difference monitored.
    if(count($currentDifference) == 1) {
        if($speed < $speedThreshold) {
            $currentDifference[] = $gpsEntry;
        }

        // Add to differences list.
        $currentDifferences[] = $currentDifference;

        // Reset current difference.
        $currentDifference = array();
    } else {
        if($speed > $speedThreshold) {
            $currentDifference[] = $gpsEntry;
        }
    }

    // Increase line count.
    $lineCount++;
}

// Check output.
var_dump($currentDifferences);
?>