PDA

View Full Version : i think i need a str function


arne2
12-08-2006, 04:01 PM
HI, i have a chatbox. A username is there given by someones singup name and the round (it's part of a game). like for example: you(12) where you is your username and 12 is your round.
Now i need a script who can split them up again to make you=$rusername and 12=$rround
(so i can use it in a query select * from table where username=$rusername and round=$rround)

Please help me if you can,

THank you very much !

ralph l mayo
12-08-2006, 04:30 PM
I think this'll work


$name = 'you(10)';
if (!preg_match('/(.*)\((\d+)\)\z/xms', $name, $match))
{
throw new Exception('Name/round parsing didn\'t work out');
}
echo "user: $match[1], round: $match[2]";