ANSI color

102 views
Skip to first unread message

valxe

unread,
Sep 7, 2012, 6:17:07 PM9/7/12
to phudbase-...@googlegroups.com
Hi, I've been messing around with this code for a few days. The next question is, how do I incorporate ANSI color so that I can colorize my game? I've looked around at the ANSI codes but I just can't really seem to figure out how to incorporate them and bring color to the game that most MUDs have.

Apocist

unread,
Sep 16, 2012, 8:20:03 PM9/16/12
to phudbase-...@googlegroups.com
For ANSI output based on defined tokens, I've made a simple function added to the output formatting.

    function pColorize($string){

        $string = str_replace("&x", " [0;30m", $string);//Black
        $string = str_replace("&b", " [0;34m", $string);//dark Blue????
        $string = str_replace("&g", " [0;32m", $string);//Green
        $string = str_replace("&c", " [0;36m", $string);//Cyan
        $string = str_replace("&r", " [0;31m", $string);//Red(blood)
        $string = str_replace("&p", " [0;35m", $string);//Purple
        $string = str_replace("&O", " [0;33m", $string);//Brown(orange)
        $string = str_replace("&w", " [0;37m", $string);//Gray
        $string = str_replace("&z", " [1;30m", $string);//Dark Gray
        $string = str_replace("&C", " [1;34m", $string);//Light Blue
        $string = str_replace("&G", " [1;32m", $string);//Light Green
        $string = str_replace("&B", " [1;34m", $string);//Blue
        //$string = str_replace("&--", " [1;36m", $string);//Light Cyan
        $string = str_replace("&R", " [1;31m", $string);//Light Red
        $string = str_replace("&P", " [1;35m", $string);//Light Purple
        $string = str_replace("&Y", " [1;33m", $string);//Yellow
        $string = str_replace("&W", " [1;37m", $string);//White
        return $string;
    }

Tim van Dijen

unread,
Jan 31, 2013, 9:16:40 AM1/31/13
to phudbase-...@googlegroups.com
Put the attached file in /wm_server/includes
Edit stringFunctions.inc and add require_once('ansi2html.php'); on top of the file...
Further down, there's a for-loop doing something with TELNET_COLORS... Comment it out, along with the 3 lines of code above..
Insert:  $string = ansi2html($string);

There ya go.. Perfect ANSI-parsing!
ansi2html.php
Reply all
Reply to author
Forward
0 new messages