I am having a string MyText (text in braces)
. I am trying to remove spaces at beginning and ending. Also, I want to remove empty braces ()
like this. For example, if my string is like this MyText ()
, I have to remove ()
and print MyText
.
My PHP code:
$str = 'MyText (text in braces) ';
echo trim($str, ' ()');
My output is MyText (text in braces
It is trimming the outer brace also. But it should not remove that.