There is some tags with missing quote. <img src=file.jpg border="0" alt=text goes here title=this is a title /> replace to: <img src="file.jpg" border="0" alt="text goes here" title="this is a title" /> How can that be done?
$str = preg_replace('`([a-z])=([^"]*?)\s+(?=[a-z]+=|/)`', '\1="\2" ', $str); Code (markup): Note that it's a fragile regex due to the fundamentally ambiguous nature of your inputs. Things like slashes and equal signs in the attribute values can mess it up.