Type(Type) 所有的發表文章

前往頁面 1 2 3 4 5 6 7 8 ... 571  下一頁→

休假愉快(2026-07-27 15:42)

👍(2026-07-27 15:41)

很熱鬧的夏天場景 👍(2026-07-27 13:25)

讚讚,活動成功出展順利 😎 👍(2026-07-27 13:23)

要把蝴蝶或蛾那些「觸鬚、頭毛」都展現出來

一方面需要一定繪圖技術,

另外一方面,
需要「不怕昆蟲」的勇氣。 😎👍(2026-07-27 13:22)

看上述:「老同事相認過程」蠻有趣的 😄(2026-07-27 13:20)

長壽老貓,
辛苦您的照顧。(2026-07-27 13:17)

左虎,右貓,上鯨,左上飛馬

為什麼選這四種動物? 😀(2026-06-29 19:41)

[h2]php.exe <taxi_uber_sum_fare.php> <eml_files_folders>[/h2]

代碼:


<?php
declare(strict_types=1);

if ($argc < 2) {
    fwrite(STDERR, "Usage: php taxi_uber_sum_fare.php <eml-directory>\n");
    exit(1);
}

$dir = $argv[1];
if (!is_dir($dir)) {
    fwrite(STDERR, "Not a directory: {$dir}\n");
    exit(1);
}

$files = glob(rtrim($dir, "\\/") . DIRECTORY_SEPARATOR . '*.eml');
sort($files, SORT_NATURAL | SORT_FLAG_CASE);

if (!$files) {
    fwrite(STDERR, "No .eml files found in {$dir}\n");
    exit(1);
}

function extractHtmlPart(string $raw): ?string
{
    if (!preg_match('/Content-Type:\s*text\/html.*?\R\R(.*?)(?=\R--=|$)/si', $raw, $m)) {
        return null;
    }
    return quoted_printable_decode($m[1]);
}

function extractAmount(string $html): ?array
{
    if (!preg_match('/data-testid="total_fare_amount"[^>]*>([^<]+)/i', $html, $m)) {
        return null;
    }

    $label = html_entity_decode(trim($m[1]), ENT_QUOTES | ENT_HTML5, 'UTF-8');
    $label = preg_replace('/\s+/u', ' ', $label);

    if (!preg_match('/([A-Z]{0,3}\$)\s*([0-9,]+(?:\.[0-9]{2})?)/u', $label, $n)) {
        if (!preg_match('/([0-9,]+(?:\.[0-9]{2})?)/u', $label, $n)) {
            return null;
        }
        $currency = '';
        $number = $n[1];
    } else {
        $currency = $n[1];
        $number = $n[2];
    }

    $number = str_replace(',', '', $number);
    $cents = (int)round(((float)$number) * 100);

    return [
        'raw' => $label,
        'currency' => $currency,
        'number' => $number,
        'cents' => $cents,
    ];
}

$rows = [];
$totalCents = 0;
$failures = [];

foreach ($files as $file) {
    $raw = file_get_contents($file);
    if ($raw === false) {
        $failures[] = basename($file) . " (read error)";
        continue;
    }

    $html = extractHtmlPart($raw);
    if ($html === null) {
        $failures[] = basename($file) . " (html not found)";
        continue;
    }

    $amount = extractAmount($html);
    if ($amount === null) {
        $failures[] = basename($file) . " (amount not found)";
        continue;
    }

    $totalCents += $amount['cents'];
    $rows[] = [
        'file' => basename($file),
        'amount' => $amount['currency'] . number_format($amount['cents'] / 100, 2, '.', ''),
    ];
}

foreach ($rows as $row) {
    echo $row['file'] . "\t" . $row['amount'] . PHP_EOL;
}

echo str_repeat('-', 40) . PHP_EOL;
echo 'Count: ' . count($rows) . PHP_EOL;
echo 'Total: ' . number_format($totalCents / 100, 2, '.', '') . PHP_EOL;

if ($failures) {
    echo str_repeat('-', 40) . PHP_EOL;
    echo "Failures:" . PHP_EOL;
    foreach ($failures as $failure) {
        echo $failure . PHP_EOL;
    }
    exit(2);
}


(2026-05-31 17:33)

❤️(2026-05-28 11:27)

🥰 🥰(2026-05-21 15:21)

🐻 俊國熊帽子,太強了(2026-05-21 14:34)

👍 👍 👍(2026-05-06 17:48)

👍 👍 👍(2026-05-06 17:48)

👍 👍 👍(2026-05-06 17:48)

我的對策: 睡到自然醒,就不會有起床氣。 😋(2026-05-06 17:47)

>> 貓的恩返,不要是小強都好

貓:「勞贖可以嗎?」 🐀(2026-05-06 17:46)

yaten 寫到:
總覺得可以做中華風版本的


❤️ ❤️ ❤️(2026-05-06 17:45)

👍 👍 👍(2026-05-06 17:36)

>> 幸好,它還是靠我的草稿生成出來。
>> 這還是原創嗎?

我認為應該算;

的確,這很難定義

但原稿是你原創,那應該沒問題。(2026-05-06 17:33)

前往頁面 1 2 3 4 5 6 7 8 ... 571  下一頁→