Hi, I'm just wondering how I could remove the text between a set of parentheses and the parentheses themselves in php. Example : ABC (Test1) I would like it to delete (Test1) and only leave ABC Thanks
You could simply use something like: <?php $blah = "ABC (Test1)"; echo substr($blah, 0, strrpos($blah, "(")); ?> Code (markup):
<?php $str = 'abc (ABC not happy :( )'; $str = preg_replace('#\([^\)]*\)#', '', $str); echo "$str\n"; ?> Code (markup):
<?php $text = 'abc (ABC)'; //this will remove text within brackets. $text = preg_replace('#\([a-z0-9]*\)#i', '', $text); print $text; ?> PHP: or if you'd prefer to replace more precisely, ie. an actual word. <?php $text = 'abc (ABC)'; $text = str_replace("(ABC)", "", $text); print $text; ?> PHP:
<?php $string = "ABC (Test1)"; $string = preg_replace("/\((.*?)\)/", "", $string); // will remove anything between brackets echo $string; // prints ABC ?> PHP: