解析mIRC颜色在php [英] Parsing mIRC colors in php

查看:237
本文介绍了解析mIRC颜色在php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过php将 mirc颜色代码转换为html。
以下是示例: http://searchirc.com/search.php?F=exact&T=chan&N=6246&I=anime-pirates

I want to convert mirc color codes to html via php. Here is the example: http://searchirc.com/search.php?F=exact&T=chan&N=6246&I=anime-pirates

感谢

推荐答案

//php.net/preg_replace_callback\">preg_replace_callback :

Use preg_replace_callback:

function mycallback($matches) {
    $bindings = array(
       0=>'white',
       1=>'black',
       2=>'blue',
       3=>'green',
       4=>'red',
       5=>'brown',
       6=>'purple',
    );

    $fg = isset($bindings[$matches[1]]) ? $bindings[$matches[1]] : 'transparent';
    $bg = isset($bindings[$matches[2]]) ? $bindings[$matches[2]] : 'transparent';

    return '<span style="color: '.$fg.'; background: '.$bg.';">'.$matches[3].'</span>';
}

$str = '^C3,1Hello^C foo ^C6,2World^C';
$str = preg_replace_callback('/\^C([0-9]{1,2}),?([0-9]{1,2})(.*?)\^C/', 'mycallback', $str);

echo $str;

这篇关于解析mIRC颜色在php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆