我想转换mirc 颜色代码 http://www.mirc.com/help/colors.html通过 php 转换为 html。
这是示例:http://searchirc.com/search.php?F=exact&T=chan&N=6246&I=anime-pirates
Thanks
Use 预替换回调 http://php.net/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;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)