$output = preg_replace('!<img src="([^"]+)" />!',"<img src=\"$1\" alt=\"$1\" />",$str);
That's what I came up with for the 2nd one. I wasn't too sure about the first. It looks like the message board messed up your code, so I didin't know exactly what to do.