SoberDude Posted June 2, 2009 Share Posted June 2, 2009 I need to use a variable in a preg_replace, like: $blah= preg_replace('$variable', 'blah', $blah); If I try to use a variable in the search part of preg_replace, it does not work. Link to comment https://forums.phpfreaks.com/topic/160576-solved-variablespreg_replace/ Share on other sites More sharing options...
lonewolf217 Posted June 2, 2009 Share Posted June 2, 2009 why do you have quotes around the variable ? it would be trying to literally use $variable as the regular expression to match it to. see the example here http://us.php.net/preg_replace If you still dont get it, we need specific code examples, not "blah blah something like this" to find the issue Link to comment https://forums.phpfreaks.com/topic/160576-solved-variablespreg_replace/#findComment-847455 Share on other sites More sharing options...
SoberDude Posted June 2, 2009 Author Share Posted June 2, 2009 why do you have quotes around the variable ? it would be trying to literally use $variable as the regular expression to match it to. see the example here http://us.php.net/preg_replace If you still dont get it, we need specific code examples, not "blah blah something like this" to find the issue I know, I was just using the variable as an example. I know it is an incorrect syntax. The actual one is more like: $newvar = preg_replace_callback('/' . $var . '([^\b\(]*.)/', "remove_caps", $newvar); Link to comment https://forums.phpfreaks.com/topic/160576-solved-variablespreg_replace/#findComment-847459 Share on other sites More sharing options...
SoberDude Posted June 2, 2009 Author Share Posted June 2, 2009 Oh wait, nevermind. Apparently my variable had a "(" in it. Link to comment https://forums.phpfreaks.com/topic/160576-solved-variablespreg_replace/#findComment-847467 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.