• MCI and ASCII for HTML

    From Darryl Perry@44:100/4 to All on Mon Sep 12 22:10:00 2016
    Hi all!

    I just wanted to share a php library I used in conjunction with the mystic_library.php library of Frank Linhares that I updated. I've used it as
    a base for my website and now I've also created a simple library that will convert MCI colors and ASCII characters into beautiful HTML images.

    I save this file as myconv.php: ----------------------------------------------------------------------
    <?php

    function myconv($line){

    $line = mci_d_replace($line);
    $line = mci_c_replace($line);
    $line = str_replace("|00", "<span style='color:black;'>", $line);
    $line = str_replace("|01", "<span style='color:darkblue;'>", $line);
    $line = str_replace("|02", "<span style='color:darkgreen;'>", $line);
    $line = str_replace("|03", "<span style='color:darkcyan;'>", $line);
    $line = str_replace("|04", "<span style='color:darkred;'>", $line);
    $line = str_replace("|05", "<span style='color:darkmagenta;'>", $line);
    $line = str_replace("|06", "<span style='color:brown;'>", $line);
    $line = str_replace("|07", "<span style='color:gray;'>", $line);
    $line = str_replace("|08", "<span style='color:darkgray;'>", $line);
    $line = str_replace("|09", "<span style='color:blue;'>", $line);
    $line = str_replace("|10", "<span style='color:lawngreen;'>", $line);
    $line = str_replace("|11", "<span style='color:cyan;'>", $line);
    $line = str_replace("|12", "<span style='color:red;'>", $line);
    $line = str_replace("|13", "<span style='color:magenta;'>", $line);
    $line = str_replace("|14", "<span style='color:yellow;'>", $line);
    $line = str_replace("|15", "<span style='color:white'>", $line);
    $line = str_replace("|16", "<span style='background-color:black;'>", $line);
    $line = str_replace("|17", "<span style='background-color:darkblue;'>", $line);
    $line = str_replace("|18", "<span style='background-color:darkgreen;'>", $line);
    $line = str_replace("|19", "<span style='background-color:darkcyan;'>", $line);
    $line = str_replace("|20", "<span style='background-color:darkred;'>", $line);
    $line = str_replace("|21", "<span style='background-color:darkmagenta;'>", $line);
    $line = str_replace("|22", "<span style='background-color:brown;'>", $line);
    $line = str_replace("|23", "<span style='background-color:darkgrey;'>", $line);
    $line = str_replace("|CL", "", $line);
    $line = str_replace("|CR", "", $line);
    $line = str_replace("|PN", "", $line);
    $line=iconv('CP437','UTF-8',$line);

    return $line;
    }

    function mci_c_replace($str){

    $cnt=substr_count($str,"|[C");
    for ($x=0;$x<$cnt;$x++){
    $pos=strpos($str,"|[C");
    $ostr=substr($str,$pos,5);
    $len=substr($str,$pos+3,2);
    $nstr=str_pad("",(int) $len," ");
    $str=str_replace($ostr,$nstr,$str);
    }
    return $str;
    }

    function mci_d_replace($str){

    $cnt=substr_count($str,"|\$D");
    for ($x=0;$x<$cnt;$x++){
    $pos=strpos($str,"|\$D");
    $ostr=substr($str,$pos,5);
    $len=substr($str,$pos+3,2)-1;
    $nchr=substr($str,$pos+5,1);
    $nstr=str_pad("",(int) $len,$nchr);
    $str=str_replace($ostr,$nstr,$str);
    }
    return $str;
    }


    -----------------------------------------------------------------------

    It can be used in your php code like this:

    <?php
    include "mconv.php";

    echo "<table>";
    echo "<tr>";
    $str=myconv("|01This |02is |03an |04example|05Mystic |06Color |07Codes");
    echo "<td>".$str."<td>";
    echo "</tr>";
    echo "</table>";


    It will also convert ASCII characters into UTF-8 HTML format.

    You can see a prime example of its use on my website. Look in the ANSI ART files area and see how the ASCII art is perfectly rendered.

    http://cyberia.darktech.org:8080/filelist.php?area=ansiart

    You can also see an example of how this converts the MCI output of a doorgame usage generator bulletin.

    http://tinyurl.com/hg9kdq6

    Let me know if this is helpful to anybody.

    "No matter where you go, there you are!" - Buckaroo Bonzai

    --- Mystic BBS v1.12 A31 (Raspberry Pi)
    * Origin: Cyberia BBS | Cyberia.Darktech.Org | Kingwood, TX (44:100/4)
  • From Pequito@44:100/12 to Darryl Perry on Tue Sep 13 10:34:00 2016
    On 09/12/16, Darryl Perry said the following...

    Hi all!

    I just wanted to share a php library I used in conjunction with the mystic_library.php library of Frank Linhares that I updated. I've used
    it as a base for my website and now I've also created a simple library that will convert MCI colors and ASCII characters into beautiful HTML images.

    OK this is pretty sweet though do we have to have it setup similar to the way you have it in the example? Here is what I attemped.

    <?php
    $data_path = '/mystic/data/';
    include 'mystic_library.php';
    include 'mconv.php';

    $oneliners=mystic_oneliners($data_path,10);
    foreach ($oneliners as $line1) {
    echo "<tr>";
    echo "<td>".myconv($line1['text'])."</td>";
    echo "<td>".$line1['from']."</td>";
    echo "</tr>";
    }


    hmm maybe its the quotes.. will try something else. :P

    --- Mystic BBS v1.12 A31 (Linux)
    * Origin: Twinkle BBS (44:100/12)
  • From Darryl Perry@44:100/4 to Pequito on Tue Sep 13 12:38:00 2016
    On 09/13/16, Pequito said the following...

    On 09/12/16, Darryl Perry said the following...

    Hi all!

    I just wanted to share a php library I used in conjunction with the mystic_library.php library of Frank Linhares that I updated. I've us it as a base for my website and now I've also created a simple librar that will convert MCI colors and ASCII characters into beautiful HTML images.

    OK this is pretty sweet though do we have to have it setup similar to
    the way you have it in the example? Here is what I attemped.

    <?php
    $data_path = '/mystic/data/';
    include 'mystic_library.php';
    include 'mconv.php';

    $oneliners=mystic_oneliners($data_path,10);
    foreach ($oneliners as $line1) {
    echo "<tr>";
    echo "<td>".myconv($line1['text'])."</td>";
    echo "<td>".$line1['from']."</td>";
    echo "</tr>";
    }


    hmm maybe its the quotes.. will try something else. :P

    How exactly is if failing? Maybe you can look in your apache or nginx error logs to see any errors if any. But looking at your code, it looks like it should work.

    Looking at the mystic_library.php, I see that the mystic_oneliners() function does not already do MCI translation. So unless the 'text' or 'from' fields have some MCI code in them, they should just be displayed with the default color.

    What you should do is try it with your file descriptions. You'll see how
    great it works there.

    "No matter where you go, there you are!" - Buckaroo Bonzai

    --- Mystic BBS v1.12 A31 (Raspberry Pi)
    * Origin: Cyberia BBS | Cyberia.Darktech.Org | Kingwood, TX (44:100/4)