2
mirc color codesをphtmlでhtmlに変換したいと思います。ここで は一例です:mIRCの色をPHPで構文解析する
mirc color codesをphtmlでhtmlに変換したいと思います。ここで は一例です:mIRCの色をPHPで構文解析する
使用preg_replace_callbackhttp://searchirc.com/search.php?F=exact&T=chan&N=6246&I=anime-pirates
ありがとう:
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;
私は私があなたのリンクの例では理解して何も表示されません。カラーコードの仕組みを説明できますか? –
http://www.mirc.com/help/colors.htmlご覧ください。 基本的に、「ctrl + k」の組み合わせの後に、各色の番号を入力します。数字の間にカンマを使用すると、背景を取得します。 – wonnie
何を解析しますか?データはどのような形で入ってくるのですか?入力ソース/メソッドとは何ですか? PHPはどのようにセットアップする必要がありますか?プリセットされたHTMLクラスを使用するか、背景色を設定しますか? – ssube