<img title="тест" id="hh" alt="fff" src="/test/" align="left" width="500" dddd="dd" height="300">
$subject = '<a attr1="val1" attr2 = "" attr3 href="/link/?pa=234kjh&ff=09" attr4="val4" title="title">привет anchor 245</a>';
$pattern = '/((?:href|title)=\"[^"]+\").+?((?:href|title)=\"[^"]+")[^>]{0,}>([^<]+)/i';
preg_match($pattern,$subject,$match);
array_shift($match);
$text = array_pop($match);
$attrs = join(' ',$match);
$a_new = '<a '.$attrs.'>'.$text.'</a>';
echo htmlspecialchars($a_new);