PHP code example of guirong / cli-message

1. Go to this page and download the library: Download guirong/cli-message library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

guirong / cli-message example snippets


$style = new Style();
$style->setForegroundColor(Style::COLOR_GREEN) // 定义颜色为绿色
      ->setBold() // 设置加粗
      ->setUnderLine(); // 设置显示下划线
$message = new Message();
$message->setStyle($style); // 给消息设定样式
$message->setContent('哈哈哈!'); // 设置消息内容
echo $message, PHP_EOL; // 重写了__toString方法,消息对象可直接作为字符串使用

// 也可以用getContentWithStyle方法来获取处理后的字符串进行输出
echo $message->getContentWithStyle(), PHP_EOL;

$anotherStyle = new Style();
$anotherStyle->setForegroundColor(Style::COLOR_RED);
echo $message->getContentWithStyle($anotherStyle, PHP_EOL);