preg_replace_callback( "/[0-9]*/", array( &$this, '_getPHPNumber' ), $code );
private function _getPHPNumber( $matches ) {
return ( $this->_getHtmlCode( $matches[0], PHP::$Colors['number'] ) );
}
private function _getHtmlCode( $text, $color ) {
$rows = array_filter( explode( "\n", $text ) );
$count = count( $rows );
$output = '';
for ( $i = 0; $i < $count; $i++ ) {
$n = ( $count > 1 ? ( $i != $count - 1 ? "\n" : "" ) : "" );
$output .= "<span style=\"color:{$color};\">{$rows[$i]}</span>{$n}";
}
return ( $output );
}
上記の出力は次のようになります。
<span style="color:#FF0000;">152</span>
数値が0の場合、出力から削除されることを除いて、これはうまく機能します。問題の原因となっている行は$rows = array_filter( explode( "\n", $text ) );にあり_getHtmlCodeます。正確な原因はarray_filterです。削除すると、出力は完全に壊れますが、0が表示されます。そのままにしておくと、0が削除されます。
これを修正する方法について何かアイデアはありますか?