[PHP] preg_replace

2003-02-18 Thread aw2001
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"=>"#FF",
  "2"=>"#00FF00",
  "3"=>"#F0FF0F",
  "4"=>"#FF",
  "5"=>"#00",
  "6"=>"#FF00FF",
  "7"=>"#FF",
  "8"=>"ltbrown",
  "9"=>"#0F00F0",
  "0"=>"#E7E7E7"
  );
  $pattern = "/\^(\d)/";
  $replacement = "$color[$1]";
  $player = preg_replace($pattern, $replacement, $player);
  return $player;
}

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




[PHP] preg_replace with /e modifier

2003-02-24 Thread aw2001
I cant find a way to properly escape the special characters for php code
evaluation (iam sure its something simple) Can some one point this out?

[errors generated]
Parse error: parse error, unexpected ']'
Fatal error: Failed evaluating code: $color[!]

[function containing error]
function HTMLfromNickName ( $player ) {
$color=array(
//numeric
"1"=>"","2"=>"","3"=>"","4"=>"","5"=>"","6"=>"","7"=>"","8"=>"","9"=>"","0"=>"",
//Caps
"Q"=>"","W"=>"","E"=>"","R"=>"","T"=>"","Y"=>"","U"=>"","I"=>"","O"=>"","P"=>"","A"=>"","S"=>"","D"=>"","F"=>"","G"=>"","H"=>"","J"=>"","K"=>"","L"=>"","Z"=>"","X"=>"","C"=>"","V"=>"","B"=>"","N"=>"","M"=>"",
//lower
"q"=>"","w"=>"","e"=>"","r"=>"","t"=>"","y"=>"","u"=>"","i"=>"","o"=>"","p"=>"","a"=>"","s"=>"","d"=>"","f"=>"","g"=>"","h"=>"","j"=>"","k"=>"","l"=>"","z"=>"","x"=>"","c"=>"","v"=>"","b"=>"","n"=>"","m"=>"",
//special
"!"=>"","@"=>"","#"=>"","\$"=>"","\%"=>"","\&"=>"","*"=>"","("=>"",")"=>"","_"=>"","-"=>"","+"=>"","="=>"","["=>"","]"=>"","{"=>"","}"=>"","'"=>"","\""=>"","?"=>"","/"=>"","|"=>"",","=>"","."=>"","<"=>"",">"=>"",":"=>"",";"=>""
);
//todo: include special characters
  $end = $end + substr_count ($player, "^");
  $player = preg_replace("/\^(.)/ex", '$color[$1]', $player);
  $player .= str_repeat ("", $end);
  return $player;
}

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



[PHP] Re: preg_replace with /e modifier

2003-02-25 Thread aw2001
Thanks John! Sorry to pester you any more, but how can I match all Ascii
characters? I can't seem to find it on
'http://www.php.net/manual/en/pcre.pattern.syntax.php'

(The period is matching Ascii characters and giving me this)
Unexpected character in input: ' ' (ASCII=23) state=2

Also how many ascii characters are there? Would it be feasible to add
them into the array?

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