I want to replace all content between (
and )
, using php.
my string:
$string = "This is a (string)";
the required output is:
$string = "This is a";
my code doesn't works:
$string = "This is a (string)";
$search = "/[^(](.*)[^)]/";
$string = preg_replace($search, "", $string);
echo $string; // output is ")"
$result = preg_replace('/\(.+?\)/sm', 'Put your text here', $string);
Try this code
Or to save () add them to replacement
$page = preg_replace('/\(.+?\)/sm', '(Put your text here)', $page);
This should work for you:
<?php
$string = "This is a (string)";
echo preg_replace("/\([^)]+\)/","",$string);
?>
Output:
This is a
Just change that:
$search = "/ *\(.*?\)/";