ShadeSlayer Posted May 5, 2009 Share Posted May 5, 2009 I have a code that I'm using to replace this: Team Player (10 points): Complete a mission on coop mode. With this: [adminbr][b]Team Player[/b] - [i]10 points[/i][adminbr][adminbr] So I have the code there that does the job fine.. unless there are parenthesis elsewhere (eg. Team Player (10 points): Complete a mission on coop mode (not XBL). Basically, one part of the replacement is taking an opening parenthesis tag and replacing it with the appropriate values, but then, it needs to be fixed for certain situations. So I tried this: $s = $_POST['string']; $p[0] = " "; $r[0] = "[adminbr][adminbr][b]"; $p[1] = "): "; $r[1] = "[/i][adminbr]"; $p[2] = "\\\""; $r[2] = "\""; $p[3] = "\'"; $r[3] = "'"; $str = str_replace($p, $r, $s); //, $string $ereg = eregi_replace(" [\(]^[0-9]{1,3}$", "[/b] - [i]", $str); echo $ereg; Which says "replace " (###" with "[/b] - [i]" and it completely ignores the $ereg. So I have a bit of a problem here that I need help with. Much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/157012-solved-regex-code-not-working/ Share on other sites More sharing options...
Ken2k7 Posted May 5, 2009 Share Posted May 5, 2009 You're missing a pair of delimiters for the Regex. Also, preg > eregi. $ereg = preg_replace("#[\(]^[0-9]{1,3}$#i", "[/b] - [i]", $str); Quote Link to comment https://forums.phpfreaks.com/topic/157012-solved-regex-code-not-working/#findComment-827088 Share on other sites More sharing options...
ShadeSlayer Posted May 6, 2009 Author Share Posted May 6, 2009 Thanks for the help, but it still doesn't work. http://gphosting.net/test2.php There's a link to the script, the link at the top will show you all the code. Only the first textbox has the code enabled, but it just ignores the preg_replace and outputs whatever the str_replace did. Quote Link to comment https://forums.phpfreaks.com/topic/157012-solved-regex-code-not-working/#findComment-827096 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Oh oops, I didn't read your first post entirely. Try this - $match = preg_replace("#\s*(Team Player)\s*\((\d+)\s*points\).*$#", "[adminbr][b]$1[/b] - [i]$2[/i][adminbr][adminbr]", $str); Quote Link to comment https://forums.phpfreaks.com/topic/157012-solved-regex-code-not-working/#findComment-827099 Share on other sites More sharing options...
ShadeSlayer Posted May 6, 2009 Author Share Posted May 6, 2009 That looks like it'll replace the whole string... I just want it to replace: (x with [/b] - [i]x where x is between 1 and 3 numbers. Quote Link to comment https://forums.phpfreaks.com/topic/157012-solved-regex-code-not-working/#findComment-827104 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Uh what do you mean x is between 1 and 3 numbers? Quote Link to comment https://forums.phpfreaks.com/topic/157012-solved-regex-code-not-working/#findComment-827108 Share on other sites More sharing options...
ShadeSlayer Posted May 6, 2009 Author Share Posted May 6, 2009 [0-9]{1, 3} Quote Link to comment https://forums.phpfreaks.com/topic/157012-solved-regex-code-not-working/#findComment-827110 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Oh sorry. $match = preg_replace("#(\d{1,3})#i", "[/b] - [i]$1", $str); Quote Link to comment https://forums.phpfreaks.com/topic/157012-solved-regex-code-not-working/#findComment-827122 Share on other sites More sharing options...
ShadeSlayer Posted May 6, 2009 Author Share Posted May 6, 2009 Alright, I ended up making it work. Thanks a bunch, now this will be a lot easier! Quote Link to comment https://forums.phpfreaks.com/topic/157012-solved-regex-code-not-working/#findComment-827250 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.