What is the proper syntax to preg_replace just the parenthesis in PHP?
$search = preg_replace('/\(\)/','',$search);
Thank you
Assuming you want to remove both ( and ) from the $search string:
$search = preg_replace('/\(|\)/','',$search);
I think the fastest way to do this is using the strtr function, like this:
$search = strtr($search, array('(' => '', ')' => ''));
                        That is the proper syntax, though preg_replace is for regular expressions, if you just want to replace () then str_replace is a couple of times faster.
If you want to replace ( or ) wherever they are, you could use
preg_replace("/\(|\)/", "", $str);
                        You mean like this?
$search = preg_replace('/[()]/', '', $search);
This will strip all parenthesis without regard to pairing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With