Nihilis Posted July 22, 2008 Share Posted July 22, 2008 Hi everybody! I'm Swiss, so my English could sound a little strange sometimes... sorry for that. I have a Problem with str_replace(). I have a large string containing an unknown amount of the substring [CHECK-00] ([CHECK-01], [CHECK-02], [CHECK-04], [CHECK-05] ...) And now I want to use str_replace to replace all of them with a empty string: '' Of course I could just count the number of "[CHECK-" substrings and replace them within a loop or something like this, but they are not always in a specific order. They could also be something like "[CHECK-87]{some substring}[CHECK-1]{some substring}" The only thing for sure is, that this [CHECK] substrings have always the same structure: "[" + "CHECK-" + {two numbers} + "]". Is there any way to do this with a combination of str_replace and regex? Or do you have an other idea on how to solve this problem? Any help is very welcome =) Greetings from Switzerland, Nihilis Quote Link to comment https://forums.phpfreaks.com/topic/116070-str_replace-with-only-semi-known-string-that-should-be-replaced/ Share on other sites More sharing options...
.josh Posted July 22, 2008 Share Posted July 22, 2008 try using preg_replace instead of str_replace Quote Link to comment https://forums.phpfreaks.com/topic/116070-str_replace-with-only-semi-known-string-that-should-be-replaced/#findComment-596836 Share on other sites More sharing options...
Nihilis Posted July 22, 2008 Author Share Posted July 22, 2008 Oh, that was easy...^^ Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/116070-str_replace-with-only-semi-known-string-that-should-be-replaced/#findComment-596838 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.