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! 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); ?> 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. 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); ?> 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. :-\ 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! 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
Archived
This topic is now archived and is closed to further replies.