3

file_get_contents数千行の重複から一意のエラーのみを返すように変更するにはどうすればよいですか

$this->data['log'] = file_get_contents($file, FILE_USE_INCLUDE_PATH, null);

<textarea wrap="off" style="width: 98%; height: 300px; padding: 5px; border: 1px solid #CCCCCC; background: #FFFFFF; overflow: scroll;"><?php echo $log; ?></textarea>

エラー:

2013-01-10 0:26:45 - PHP Notice:  Undefined index: name in /var/www/example/public/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 159
2013-01-10 0:27:02 - PHP Notice:  Undefined index: name in /var/www/example/public/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 159
2013-01-10 0:27:04 - PHP Notice:  Undefined index: name in /var/www/example/public/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 159
2013-01-10 0:29:25 - PHP Notice:  Undefined variable: thumb in /var/www/example/public/catalog/view/theme/example/template/product/manufacturer_info.tpl on line 23
2013-01-10 0:29:25 - PHP Notice:  Undefined variable: description in /var/www/example/public/catalog/view/theme/example/template/product/manufacturer_info.tpl on line 23
2013-01-10 0:29:25 - PHP Notice:  Undefined variable: categories in /var/www/example/public/catalog/view/theme/example/template/product/manufacturer_info.tpl on line 34
2013-01-10 0:29:25 - PHP Notice:  Undefined variable: categories in /var/www/example/public/catalog/view/theme/example/template/product/manufacturer_info.tpl on line 98
2013-01-10 2:46:25 - PHP Notice:  Undefined index: name in /var/www/example/public/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 159
2013-01-10 6:09:58 - PHP Notice:  Undefined variable: thumb in /var/www/example/public/catalog/view/theme/example/template/product/manufacturer_info.tpl on line 23
2013-01-10 6:09:58 - PHP Notice:  Undefined variable: description in /var/www/example/public/catalog/view/theme/example/template/product/manufacturer_info.tpl on line 23
2013-01-10 6:09:58 - PHP Notice:  Undefined variable: categories in /var/www/example/public/catalog/view/theme/example/template/product/manufacturer_info.tpl on line 34
2013-01-10 6:09:58 - PHP Notice:  Undefined variable: categories in /var/www/example/public/catalog/view/theme/example/template/product/manufacturer_info.tpl on line 98
2013-01-10 9:54:45 - PHP Notice:  Undefined index: name in /var/www/example/public/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 159
2013-01-10 10:43:53 - PHP Notice:  Undefined index: name in /var/www/example/public/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 159
2013-01-10 12:03:27 - PHP Notice:  Undefined index: name in /var/www/example/public/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 159
2013-01-10 12:03:37 - PHP Notice:  Undefined index: name in /var/www/example/public/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 159
2013-01-10 12:03:44 - PHP Notice:  Undefined index: name in /var/www/example/public/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 159
2013-01-10 13:46:37 - PHP Warning:  imagecreatetruecolor() [<a href='function.imagecreatetruecolor'>function.imagecreatetruecolor</a>]: Invalid image dimensions in /var/www/example/public/vqmod/vqcache/vq2-system_library_image.php on line 241
2013-01-10 13:46:37 - PHP Warning:  imagecolorallocate() expects parameter 1 to be resource, boolean given in /var/www/example/public/vqmod/vqcache/vq2-system_library_image.php on line 249
2013-01-10 13:46:37 - PHP Warning:  imagefilledrectangle() expects parameter 1 to be resource, boolean given in /var/www/example/public/vqmod/vqcache/vq2-system_library_image.php on line 252
2013-01-10 13:46:37 - PHP Warning:  imagecopyresampled() expects parameter 1 to be resource, boolean given in /var/www/example/public/vqmod/vqcache/vq2-system_library_image.php on line 254
2013-01-10 13:46:37 - PHP Warning:  imagecreatetruecolor() [<a href='function.imagecreatetruecolor'>function.imagecreatetruecolor</a>]: Invalid image dimensions in /var/www/example/public/vqmod/vqcache/vq2-system_library_image.php on line 241
2013-01-10 13:46:37 - PHP Warning:  imagecolorallocate() expects parameter 1 to be resource, boolean given in /var/www/example/public/vqmod/vqcache/vq2-system_library_image.php on line 249
2013-01-10 13:46:37 - PHP Warning:  imagefilledrectangle() expects parameter 1 to be resource, boolean given in /var/www/example/public/vqmod/vqcache/vq2-system_library_image.php on line 252
2013-01-10 13:46:37 - PHP Warning:  imagecopyresampled() expects parameter 1 to be resource, boolean given in /var/www/example/public/vqmod/vqcache/vq2-system_library_image.php on line 254

完全なコード: Jay の助けを借りて

$this->data['log'] = file_get_contents($file, FILE_USE_INCLUDE_PATH, null);

と置換する:

$input = file_get_contents($file, FILE_USE_INCLUDE_PATH, null);
$temp = preg_replace('~\d{4}-\d\d-\d\d \d\d?:\d\d:\d\d - ~', '', $input);
$this->data['log'] = implode(PHP_EOL, array_unique(explode(PHP_EOL, $temp)));

vqmod

<file name="admin/controller/tool/error_log.php">
    <operation>
        <search position="before"><![CDATA[
        $this->data['clear'] = $this->url->link('tool/error_log/clear', 'token=' . $this->session->data['token'], 'SSL');
        ]]></search>
        <add><![CDATA[
        $this->data['action'] = $this->url->link('tool/error_log', 'token=' . $this->session->data['token'], 'SSL');
        ]]></add>
    </operation>
    <operation>
        <search position="after"><![CDATA[
        $this->data['log'] = file_get_contents($file, FILE_USE_INCLUDE_PATH, null);
        ]]></search>
        <add><![CDATA[
        if (!isset($this->request->post['unique'])){
            $this->data['unique'] = '';
        } else {
            $this->data['unique'] = $this->request->post['unique'];

            $temp = preg_replace('~\d{4}-\d\d-\d\d \d\d?:\d\d:\d\d - ~', '', $this->data['log']);
            $this->data['log'] = implode(PHP_EOL, array_unique(explode(PHP_EOL, $temp)));
        }
        ]]></add>
    </operation>
</file>
<file name="admin/view/template/tool/error_log.tpl">
    <operation>
        <search position="after"><![CDATA[
        $button_clear
        ]]></search>
        <add><![CDATA[
        <form action="<?php echo $action; ?>" method="post" class="buttons">
          <label>
            <input type="checkbox" name="unique" onchange="this.form.submit();" value="1" <?php if($unique){ echo ' checked="checked"'; } ?> /> Unique
          </label>
        </form>
        ]]></add>
    </operation>
</file>
4

2 に答える 2

2

これを行うには非常に簡単な方法があります。エラー ログ テキストを に設定してから$input

$temp = preg_replace('~\d{4}-\d\d-\d\d \d\d?:\d\d:\d\d - ~', '', $input);
$output = implode(PHP_EOL, array_unique(explode(PHP_EOL, $temp)));

echo $output;
于 2013-01-10T16:57:57.990 に答える
1

このコード行は、一意のエラー行を取得する場合にのみ使用してください

$errors = array();
foreach(file($file)) as $error_line) {
    $regex = '/^([0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{2}:[0-9]{2}:[0-9]{2})\s-\s(.+)$/';
    preg_match($regex, $error_line, $match);

    $hash = md5($match[2]);

    if (!isset($errors[$hash])) {
        $errors[$hash] = array(
            'error_line' => $match[2],
            'times' = array(
                $match[1],
            ),
        );
    } else {
        $errors[$hash]['times'][] = $match[1];
    }
}
于 2013-01-10T12:28:26.793 に答える