<?php $s = " MyText (text in braces) ";echo preg_replace('~^\s+|(?:\s+|\(\)\s*)$~', '', $s);
Standard input is empty
MyText (text in braces)
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!