-1

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.

Till Helge
  • 9,253
  • 2
  • 40
  • 56
Gireesh Doddipalli
  • 490
  • 2
  • 9
  • 29

1 Answers1

4

Try this

<?php
    $str = 'MyText (text in braces) ';
    echo trim(str_replace("()", "", $str));
b0ne
  • 653
  • 3
  • 10