Hello here is my function to make working colors prefix from Call of Duty. Prefix for color is for example ^1 = red

But this code looks like doesn't work on the newest php.

function colorize( $s ) {
	$s = htmlSpecialChars( $s );
	$t = $s;
	global $numtags;
	global $add;
	
	$a = array( "red", "#000", "#a8e61d", "#fff200", "#0000d1", "#00c9cd", "#cb00ce", "#696164", "#eb93bb", "#dcdcdc" );
	for( $i = 0; $i < count( $a ); $i++ ) $s = str_replace( '^^' . $i . $i, '<span style="color:' . $a[ $i ] . '";">', $s );	
    for( $i = 0; $i < count( $a ); $i++ ) $s = str_replace( '^' . $i, '<span style="color:' . $a[ $i ] . '";">', $s );		
	$spans = preg_match_all( '/\^[0-9]/U', $t, $matches );
	for( $i = 1; $i <= $numtags; $i++ ) $add .= '</span>';
    return $s . $add;
}

    "Doesn't work" needs more detail. Like: what makes you think it has something to do with the PHP version?

      The fact that the function depends on global variables makes it prone to breaking if anything unexpected has happened to those variables. They also make it more difficult to test the function in isolation, as opposed to passing them to the function arguments (by reference if needed).

        Mind you, I'm wondering what sort of markup would need a line like for( $i = 1; $i <= $numtags; $i++ ) $add .= '</span>'; to be written for it (which line, I have to point out, is solely dependent on those global variables and has nothing to do with the function's argument).

          I need it for server statistics

          ^ Means a color in game for example ^ 1 = red ^ 2 = green

          If you don't know still just visit zom.rostojek.com and check at server status. Bot called Fagiosteals0 is green in game his nickname is ^ 2fagiosteals0

            Write a Reply...