-1

Say you have a string like this:

This is a string (with parenthesis stuff)

How would you change that to

This is a string

?

Talon
  • 4,937
  • 10
  • 43
  • 57

3 Answers3

2

Replace it:

preg_replace('/\(.*?\)/', '', $str);
Blender
  • 289,723
  • 53
  • 439
  • 496
1

Use a regex.

Replace \([^)]*\) with the empty string.

Note: If there's more than one pair of parenthesis this will replace the innermost one.

Patashu
  • 21,443
  • 3
  • 45
  • 53
1

try this

  $string = "This is a string (with parenthesis stuff)";
  echo preg_replace("/\([^)]+\)/","",$string); // 'ABC '

or you can do this also

  $str = "This is a string (with parenthesis stuff)";
  $str = trim(preg_replace('/\s*\([^)]*\)/', '', $str));
thumber nirmal
  • 1,639
  • 3
  • 16
  • 27