DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone >

Colorized Text From Php In Unix Terminals

Snippets Manager user avatar by
Snippets Manager
·
Jan. 16, 07 · · Code Snippet
Like (0)
Save
Tweet
899 Views

Join the DZone community and get the full member experience.

Join For Free
Colorized text from php in unix terminals


# first define colors to use
$_colors = array(
        LIGHT_RED      => "[1;31m",
        LIGHT_GREEN     => "[1;32m",
        YELLOW         => "[1;33m",
        LIGHT_BLUE     => "[1;34m",
        MAGENTA     => "[1;35m",
        LIGHT_CYAN     => "[1;36m",
        WHITE         => "[1;37m",
        NORMAL         => "[0m",
        BLACK         => "[0;30m",
        RED         => "[0;31m",
        GREEN         => "[0;32m",
        BROWN         => "[0;33m",
        BLUE         => "[0;34m",
        CYAN         => "[0;36m",
        BOLD         => "[1m",
        UNDERSCORE     => "[4m",
        REVERSE     => "[7m",

);
##############################################
# Output colorized text to terminal run
# php scripts..
##############################################
function termcolored($text, $color="NORMAL", $back=1){
    global $_colors;
    $out = $_colors["$color"];
    if($out == ""){ $out = "[0m"; }
    if($back){
        return chr(27)."$out$text".chr(27)."[0m";#.chr(27);
    }else{
        echo chr(27)."$out$text".chr(27).chr(27)."[0m";#.chr(27);
    }//fi
}// end function
##############################################
terminal

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Usage of Java Streams and Lambdas in Selenium WebDriver
  • The Most Popular Technologies for Java Microservices Right Now
  • Simulators vs. Emulators: What's the Difference
  • Image Classification Using SingleStore DB, Keras, and Tensorflow

Comments

Partner Resources

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo