DEV Community

Cover image for Colors in PHP command line output
STNDC
STNDC

Posted on

9 3

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay