stubarny1 Posted July 4, 2011 Share Posted July 4, 2011 $variable = "Test string with (brackets)"; $str = preg_replace("/ \(.+/", "", $variable); echo $str; Hello all, I'm trying to remove the section " (brackets)" from $variable above. I don't understand why the regular expression in my preg_replace operation above didn't work. Please can someone help? Thanks, Stu Link to comment https://forums.phpfreaks.com/topic/241094-using-preg_replace-to-remove-a-word-and-its-surrounding-brackets/ Share on other sites More sharing options...
QuickOldCar Posted July 4, 2011 Share Posted July 4, 2011 <?php $variable = "Test string with (brackets)"; $str = preg_replace('~\(.*?\)~', '', $variable); echo $str; ?> Link to comment https://forums.phpfreaks.com/topic/241094-using-preg_replace-to-remove-a-word-and-its-surrounding-brackets/#findComment-1238342 Share on other sites More sharing options...
stubarny1 Posted July 5, 2011 Author Share Posted July 5, 2011 Thanks QuickOldCar Link to comment https://forums.phpfreaks.com/topic/241094-using-preg_replace-to-remove-a-word-and-its-surrounding-brackets/#findComment-1238614 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.