CitizenErased Posted December 15, 2011 Share Posted December 15, 2011 Hi is there anyway to check a string for any instances of something like this "(3)" where the number "3" could be any integer. So basically I want to search a string for any instances of a integer in brackets "(integer)" and remove it. So my string was something like $string = "String (2) string string string (7)" function($string) output would be "String string string string" where there integers in brackets could be any number Quote Link to comment https://forums.phpfreaks.com/topic/253268-remove-changing-substrings-from-string/ Share on other sites More sharing options...
scootstah Posted December 15, 2011 Share Posted December 15, 2011 $string = "String (2) string string string (7)"; function removeIntegers($string) { return preg_replace('/(\([0-9]\))+/', '', $string); } Quote Link to comment https://forums.phpfreaks.com/topic/253268-remove-changing-substrings-from-string/#findComment-1298287 Share on other sites More sharing options...
CitizenErased Posted December 15, 2011 Author Share Posted December 15, 2011 This works but is there any way to make the range larger say 1-50 I tried replacing 9 with 50 but it didn't work Quote Link to comment https://forums.phpfreaks.com/topic/253268-remove-changing-substrings-from-string/#findComment-1298294 Share on other sites More sharing options...
scootstah Posted December 15, 2011 Share Posted December 15, 2011 $string = "String (2) string string string (7)"; function removeIntegers($string) { return preg_replace('/(\([0-9]+\))/', '', $string); } Fixed. Quote Link to comment https://forums.phpfreaks.com/topic/253268-remove-changing-substrings-from-string/#findComment-1298298 Share on other sites More sharing options...
CitizenErased Posted December 15, 2011 Author Share Posted December 15, 2011 Thank you Quote Link to comment https://forums.phpfreaks.com/topic/253268-remove-changing-substrings-from-string/#findComment-1298302 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.