$text = '<a href="http://(ya).ru">Яндекс</a> sdf ( sfsdfs ( <dfgdfg(>';
$text = preg_replace('/\((?=[^<>]*>)/', '1', $text);
$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]);
},
$text
);