Here is the path "not preg_replace":
<?
$text = 'remove this text (keep this text)' ;
$start = strpos($text,"(") ;
$end = strpos($text,")") ;
echo substr($text,$start+1,$end-$start-1) ;
echo substr($text,$start,$end-$start+1) ;
?>
Note:
- This only extracts the first pair of brackets.
- Replace strpos () with strrpos () to get the last pair of brackets.
- Nested brackets cause problems.
source
share