replace anything in brackets in a string using preg_replace regex php

Lets say we have a string like this

hi there im a string (not really a string).

and we want to remove this bit

(not really a string)

We can do this using the following regex (preg_replace)

$string = "hi there im a string (not really a string)."; 
echo preg_replace("/\([^)]+\)/","",$string); // 'hi there im a string.'

Demo

Other Items in php
Page Views

This page has been viewed 126 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹