A better idea would be to stop using messing with your quotes. Just sprintf()
for outputting the HTML:
$link = sprintf('<img src="%s/data/num_%s.png" alt="%s"/>', $lname, $row, $row);
Also, while looking at your source, use your browser's View-Source feature, and not Firebug. It may be having it's own issues, as Ben said in the comments.
And to make sure you're not misreading the information, you can use a neat little header()
trick:
header('Content-Type: text/plain');
PHP uses Content-Type text/html
by default. Add this to the top of your script, and it'll display the HTML without any formatting and you can see what's really going on.