- <?
- function m2h($t) {
- //gestion couleurs mirc
- //Codes couleurs mirc de base : récupérables par /col :
- //Alias col { var %i 0,%j | while (%i <= 15) { %j = %j $color(%i) | inc %i } | echo -a %j }
- $c = explode(" ","16777215 0 8323072 37632 255 127 10223772 32764 65535 64512 9671424 16776960 16515072 16711935 8355711 13816530");
- $d = array_map("m2h_colors",$c);
- //codes ascii : b > 2 , k > 3 , o > 15 , r > 22 , u > 31
- //remplacement des Ctrl+K non valides
- $t = preg_replace("#".chr(3)."(?!\d)#",chr(15),$t);
- //substitutions gras
- $pattern_b = "!".chr(2)."(.*?)(".chr(2)."|".chr(15)."|$|(?=<br ?/?>))!i";
- $t = preg_replace($pattern_b,"<b>$1</b>$2",$t);
- //substitution soulignés
- $pattern_u = "!".chr(31)."(.*?)(".chr(31)."|".chr(15)."|$|(?=<br ?/?>))!i";
- $t = preg_replace($pattern_u,"<u>$1</u>$2",$t);
- $t = preg_replace("!(?:<b></b>|<u></u>)!i","",$t);
- //Ctrl + O et Reverse
- $a1 = array(chr(15),chr(22),chr(2),chr(31));
- $a2 = array(chr(3)."01,00",chr(3)."00,01","","");
- $t = str_replace($a1,$a2,$t);
- //substitution des ctrl + K
- while (preg_match("!^(.*)".chr(3)."(\d{0,2},?\d{0,2})(.*?)(?:".chr(3)."|$|(?=<br ?/?>))(.*)!i",$t,$matches)) {
- $k = explode(",",$matches[2]);
- $k0 = 1;
- $k1 = 0;
- $k = array_map("abs",$k);
- if ( ($k[0] >= 0) && ($k[0] <= 15) ) {
- $k0 = $k[0];
- }
- if ( (array_key_exists('1',$k)) && ($k[1] >= 0) && ($k[1] <= 15) ) {
- $k1 = $k[1];
- }
- $couleur0 = $d[$k0];
- $couleur1 = $d[$k1];
- $couleur = "<span style=\"color:".$couleur0.";background-color:".$couleur1."\">";
- $t = $matches[1].$couleur.$matches[3]."</span>".$matches[4];
- }
- return stripslashes($t);
- }
- function m2h_colors($color) {
- //conversion couleurs mirc en R,G,B puis en format couleur Web
- //passage au R,G,B
- $b = $color - $color % (256*256);
- $g = ($color - $b) - ($color - $b) % 256;
- $r = $color % 256;
- $b = $b / (256*256);
- $g = $g / 256;
- $c = explode(' ',"$r $g $b");
- $c = array_map("dechex",$c);
- $c = array_map("m2h_format",$c);
- $color = implode('',$c);
- return '#' . $color;
- }
- function m2h_format($n) {
- //force la longueur d'un nombre à deux caractères
- if (strlen($n) >= 2) {
- return $n;
- }
- return '0'.$n;
- }
- ?>
<?
function m2h($t) {
//gestion couleurs mirc
//Codes couleurs mirc de base : récupérables par /col :
//Alias col { var %i 0,%j | while (%i <= 15) { %j = %j $color(%i) | inc %i } | echo -a %j }
$c = explode(" ","16777215 0 8323072 37632 255 127 10223772 32764 65535 64512 9671424 16776960 16515072 16711935 8355711 13816530");
$d = array_map("m2h_colors",$c);
//codes ascii : b > 2 , k > 3 , o > 15 , r > 22 , u > 31
//remplacement des Ctrl+K non valides
$t = preg_replace("#".chr(3)."(?!\d)#",chr(15),$t);
//substitutions gras
$pattern_b = "!".chr(2)."(.*?)(".chr(2)."|".chr(15)."|$|(?=<br ?/?>))!i";
$t = preg_replace($pattern_b,"<b>$1</b>$2",$t);
//substitution soulignés
$pattern_u = "!".chr(31)."(.*?)(".chr(31)."|".chr(15)."|$|(?=<br ?/?>))!i";
$t = preg_replace($pattern_u,"<u>$1</u>$2",$t);
$t = preg_replace("!(?:<b></b>|<u></u>)!i","",$t);
//Ctrl + O et Reverse
$a1 = array(chr(15),chr(22),chr(2),chr(31));
$a2 = array(chr(3)."01,00",chr(3)."00,01","","");
$t = str_replace($a1,$a2,$t);
//substitution des ctrl + K
while (preg_match("!^(.*)".chr(3)."(\d{0,2},?\d{0,2})(.*?)(?:".chr(3)."|$|(?=<br ?/?>))(.*)!i",$t,$matches)) {
$k = explode(",",$matches[2]);
$k0 = 1;
$k1 = 0;
$k = array_map("abs",$k);
if ( ($k[0] >= 0) && ($k[0] <= 15) ) {
$k0 = $k[0];
}
if ( (array_key_exists('1',$k)) && ($k[1] >= 0) && ($k[1] <= 15) ) {
$k1 = $k[1];
}
$couleur0 = $d[$k0];
$couleur1 = $d[$k1];
$couleur = "<span style=\"color:".$couleur0.";background-color:".$couleur1."\">";
$t = $matches[1].$couleur.$matches[3]."</span>".$matches[4];
}
return stripslashes($t);
}
function m2h_colors($color) {
//conversion couleurs mirc en R,G,B puis en format couleur Web
//passage au R,G,B
$b = $color - $color % (256*256);
$g = ($color - $b) - ($color - $b) % 256;
$r = $color % 256;
$b = $b / (256*256);
$g = $g / 256;
$c = explode(' ',"$r $g $b");
$c = array_map("dechex",$c);
$c = array_map("m2h_format",$c);
$color = implode('',$c);
return '#' . $color;
}
function m2h_format($n) {
//force la longueur d'un nombre à deux caractères
if (strlen($n) >= 2) {
return $n;
}
return '0'.$n;
}
?>