simoneast / simple-ansi-colors
Simple PHP class for converting basic HTML-like color tags into ANSI escape codes for use in console apps and scripts. Auto-detection for Windows/Ansicon users included.
Installs: 32 193
Dependents: 9
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 3
Open Issues: 1
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-11-09 16:42:50 UTC
README
Simple PHP class for converting basic HTML-like color tags into ANSI escape codes for use in console apps and scripts.
Can be disabled through a single variable so that no colors are output (such as if the output needs to be piped to another app or script).
Auto-detection for Windows/ANSICON users included. Colors are disabled by default on Windows unless ANSICON is detected.
Version 1.0.1
MIT Licence
Requires PHP 5.3 or above.
How to use
- Include the class in your script:
require('simple-ansi-colors.php');
- Output some text:
echo Ansi::tagsToColors('<green>Hello <yellow>World!');
Note that unlike HTML, there are no closing tags. Simply use <reset>
to return the color to the default. For example...
<green>This text will be green. <reset>This text will return to the default color.
Supported tags
<black>
<red>
<green>
<yellow>
<blue>
<magenta>
<cyan>
<white>
<gray>
<darkRed>
<darkGreen>
<darkYellow>
<darkBlue>
<darkMagenta>
<darkCyan>
<darkWhite>
<darkGray>
<bgBlack>
<bgRed>
<bgGreen>
<bgYellow>
<bgBlue>
<bgMagenta>
<bgCyan>
<bgWhite>
<bold>
<italics>
<reset>
Run php demo.php
to view a sample of all the options available. In consoles with ANSI color support, you'll see the following...
In the Windows command prompt (without ANSICON), color tags will simply be stripped out.
Windows users can download ANSICON and install it by running ansicon -i
from a command prompt or "Run" window. This will allow them to view colors.