-5

I want to remove everything inside () in a string. For example if my string is $string = "this is an example string (this is the part i want to remove)";

I tried it with str_replace but naturally it just replaces "(" and not the content inside it. How can I do that since i won't know the contents beforehand?

2 Answers2

0

this might work

preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', $String);
Mohammad hayajneh
  • 623
  • 2
  • 11
  • 32
0
$string = "this is an example string (this is the part i want to remove)";
$string2=preg_replace("/\([^)]+\)/","",$string);

Try this one

pr1nc3
  • 8,108
  • 3
  • 23
  • 36