DEV Community

Cover image for Colors in PHP command line output
STNDC
STNDC

Posted on

Colors in PHP command line output

It's always good to colorize the output of the command line. Give a custom style. In this case, you can use color codes on strings to color the output. One very important thing to note is that these colors will only work on the command line and not in your browser.

Image description

Let's see the syntax:

echo "\e[1;37;42mHello World\e[0m\n";

The above command returns "Hello World" in white font and green background. You can see that the first part of the string, \e, is the escape character to open and close the string.

[0;31;42m, this is what sets the color (0;31) and background (42). This should be followed by the text that we are coloring.

In Skater I use it to style when the -help command is required.

Image description

There are few colors, but enough to give style to outings. I share the list of colors. See you soon!

# Text Colors           Code
# ---------------------------
# Black                 0;30
# White                 1;37
# Dark Grey             1;30
# Red                   0;31
# Green                 0;32
# Brown                 0;33
# Yellow                1;33
# Blue                  0;34
# Magenta               0;35
# Cyan                  0;36
# Light Cyan            1;36
# Light Grey            0;37
# Light Red             1;31
# Light Green           1;32
# Light Blue            1;34
# Light Magenta         1;35

# Background Colors     Code
# ---------------------------
# Black                 40
# Red                   41
# Green                 42
# Yellow                43
# Blue                  44
# Magenta               45
# Cyan                  46
# Light Grey            47
Enter fullscreen mode Exit fullscreen mode

Top comments (0)