leo-nog/colorfy

1.1.0 2024-01-27 21:37 UTC

This package is auto-updated.

Last update: 2024-09-28 15:23:50 UTC


README

这是一个简单的PHP库,用于美化你的控制台/浏览器返回结果,使其看起来更酷!

安装

要安装PHP Colorfy,只需运行

composer require leo-nog\colorfy

如何使用

要美化你的控制台,可以像上面的示例那样操作

文本颜色

<?php
require __DIR__.'vendor/autoload.php';

use Colorfy/Colorfy;

echo Colorfy::default("Important text here\n"); // Default color selected on terminal (or black if displaying on browser)
echo Colorfy::black("Important text here\n"); // Black
echo Colorfy::white("Important text here\n"); // White
echo Colorfy::gray("Important text here\n"); // Gray
echo Colorfy::red("Important text here\n"); // Red
echo Colorfy::green("Important text here\n"); // Green
echo Colorfy::blue("Important text here\n"); // Blue
echo Colorfy::yellow("Important text here\n"); // Yellow
echo Colorfy::magenta("Important text here\n"); // Magenta
echo Colorfy::cyan("Important text here\n"); // Cyan
echo Colorfy::lightGray("Important text here\n"); // Light Gray
echo Colorfy::lightRed("Important text here\n"); // Light Red
echo Colorfy::lightGreen("Important text here\n"); // Light Green
echo Colorfy::lightBlue("Important text here\n"); // Light Blue
echo Colorfy::lightYellow("Important text here\n"); // Light Yellow
echo Colorfy::lightMagenta("Important text here\n"); // Light Magenta
echo Colorfy::lightCyan("Important text here\n"); // Light Cyan

背景颜色

<?php
require __DIR__.'vendor/autoload.php';

use Colorfy/Colorfy;

echo Colorfy::default("Important text here\n", 'default'); // Default color selected on terminal (or white if displaying on browser)
echo Colorfy::default("Important text here\n", 'black'); // Black
echo Colorfy::default("Important text here\n", 'white'); // White
echo Colorfy::default("Important text here\n", 'gray'); // Gray
echo Colorfy::default("Important text here\n", 'red'); // Red
echo Colorfy::default("Important text here\n", 'green'); // Green
echo Colorfy::default("Important text here\n", 'blue'); // Blue
echo Colorfy::default("Important text here\n", 'yellow'); // Yellow
echo Colorfy::default("Important text here\n", 'magenta'); // Magenta
echo Colorfy::default("Important text here\n", 'cyan'); // Cyan
echo Colorfy::default("Important text here\n", 'lightGray'); // Light Gray
echo Colorfy::default("Important text here\n", 'lightRed'); // Light Red
echo Colorfy::default("Important text here\n", 'lightGreen'); // Light Green
echo Colorfy::default("Important text here\n", 'lightBlue'); // Light Blue
echo Colorfy::default("Important text here\n", 'lightYellow'); // Light Yellow
echo Colorfy::default("Important text here\n", 'lightMagenta'); // Light Magenta
echo Colorfy::default("Important text here\n", 'lightCyan'); // Light Cyan

兼容性

PHP Colorfy库支持终端和浏览器客户端,通过相同的代码将返回结果适配到每种情况。以下是一个示例

<?php

include __DIR__.'vendor/autoload.php';

use Colorfy\Colorfy;

echo Colorfy::white('Error! Please, try again later.', red);

该示例的结果是

控制台

image

浏览器

image