$text= '<a href=")()f()ghß()fg()hü">dfg</a> &ü ß !á(&gh) <&á>';
$text = preg_replace('/<a\s[^<>]*href="[^"]*\K\)/', '1', $text);
$text = preg_replace_callback(
'/<a\s[^<>]*href="\K[^"]+/',
function ($m) {
return str_replace('(', '1', $m[0]);
return str_replace(')', '2', $m[0]);
},
$text
);