php echo 终端 颜色

function colorize($text, $status)
{
    $out = "";
    switch ($status) {
        case "SUCCESS":
        case "Green":
            $out = "[32m"; //Green  
            break;
        case "FAILURE":
        case "Red":
            $out = "[31m"; //Red  
            break;
        case "WARNING":
        case "Yellow":
            $out = "[33m"; //Yellow  
            break;
        case "NOTE":
        case "Blue":
            $out = "[34m"; //Blue  
            break;
        default:
            throw new Exception("Invalid status: " . $status);
    }
    return chr(27) . "$out" . "$text" . chr(27) . "[0m";
}
echo colorize("table updating complete.\n","Green");
echo colorize("table err. \n","Red");
posted @ 2020-06-10 15:16  TBHacker  阅读(439)  评论(0编辑  收藏  举报