> This should work (as far as I can tell) But yields the following
error.
> Parse error: parse error, unexpected T_CHARACTER, expecting T_STRING
or
> T_VARIABLE or T_NUM_STRING
> Any help is appreciated!
> 
> function HTMLfromNickName ( $player ) {
> //example input "^2pla^3yer"
>   $color=array(
>       "1"=>"#FF0000",
>       "2"=>"#00FF00",
>       "3"=>"#F0FF0F",
>       "4"=>"#0000FF",
>       "5"=>"#00FFFF",
>       "6"=>"#FF00FF",
>       "7"=>"#FFFFFF",
>       "8"=>"ltbrown",
>       "9"=>"#0F00F0",
>       "0"=>"#E7E7E7"
>       );
>   $pattern = "/\^(\d)/";
>   $replacement = "$color[$1]";
>   $player = preg_replace($pattern, $replacement, $player);
>   return $player;
> }

You have a $1, which is not valid unless it's inside a "replacement"
string. It's not where you have it.

Anyway, you need an 'e' modifier to make this work. Use these two lines:

  $pattern = "/\^(\d)/e";
  $replacement = '$color[$1]';

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to