Search code examples
phpcommand-linestyles

How do I style text in console using php? [running in PHP CLI]


How do I style text in console using php? [running in PHP CLI]

Lets say that I want to have yellow bold text with blue background:

EDIT:

The code below is just an example, I am well aware that it is not working. I asked this question before and people told me that I have to be more specific.

echo "Lorem unem ipsum. <span style="color: yellow; font-wieght: bold; background-color: blue;">This is yellow bold text with blue background.</span> Dip dunem sipsum."

Solution

  • If you're aiming to output to a *nix console, you need to use ANSI escape codes. There are some packages you can use that wrap these escape codes in an easy API, like ansi-php.