dmarquard Posted May 6, 2008 Share Posted May 6, 2008 I'm not sure how to do this, but my goal is to replace: test_param = "[insert wildcard character here]" ...with: test_param = "id-12345" Any help would be greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/104314-solved-help-formatting-a-preg_replace-function/ Share on other sites More sharing options...
sasa Posted May 6, 2008 Share Posted May 6, 2008 <?php $a = 'rgr sasasaa test_param = "[insert wildcard character here] blah xxx"'; $b = 'test_param = "id-12345"'; echo preg_replace('/test_param = "\[.*?\]/', $b, $a); ?> Quote Link to comment https://forums.phpfreaks.com/topic/104314-solved-help-formatting-a-preg_replace-function/#findComment-534131 Share on other sites More sharing options...
dmarquard Posted May 6, 2008 Author Share Posted May 6, 2008 <?php $a = 'rgr sasasaa test_param = "[insert wildcard character here] blah xxx"'; $b = 'test_param = "id-12345"'; echo preg_replace('/test_param = "\[.*?\]/', $b, $a); ?> I think you may have taken my [insert wildcard character here] statement too seriously. I'm looking to search for all instances of test_param = "*" with my replacement code. I tried your above code, and it didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/104314-solved-help-formatting-a-preg_replace-function/#findComment-534273 Share on other sites More sharing options...
thebadbad Posted May 6, 2008 Share Posted May 6, 2008 Try <?php $a = 'rgr sasasaa test_param = "[insert wildcard character here] blah xxx"'; $b = 'test_param = "id-12345"'; echo preg_replace('/test_param = ".*?"/', $b, $a); ?> Quote Link to comment https://forums.phpfreaks.com/topic/104314-solved-help-formatting-a-preg_replace-function/#findComment-534278 Share on other sites More sharing options...
dmarquard Posted May 6, 2008 Author Share Posted May 6, 2008 Try <?php $a = 'rgr sasasaa test_param = "[insert wildcard character here] blah xxx"'; $b = 'test_param = "id-12345"'; echo preg_replace('/test_param = ".*?"/', $b, $a); ?> No luck, still. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/104314-solved-help-formatting-a-preg_replace-function/#findComment-534281 Share on other sites More sharing options...
dmarquard Posted May 6, 2008 Author Share Posted May 6, 2008 Actually, I did get it working with that. It was a mistake in my code. Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/104314-solved-help-formatting-a-preg_replace-function/#findComment-534283 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.