
You'll find this is article number 2554 on this blog ... with article number 1 written as long ago as 5th August 2004. I didn't plan that I would still be writing five years later (I thought, to be frank, that I would run out of things to say in a few weeks), nor did I properly anticipate the amount of traffic that would arrive at our web site through the archives.
Hindsight is marvellous, and with hindsight I would have included "alt" attributes with each image. That is so that the search engines know what the pictures show, and so that users for whom graphics are not suitable are offered an alternative. But I didn't start off with such attributes and, thousands of posts later, they're difficult to go back and add. However, in the intervening time I have also moved on to hold newly added images in a database, and as well as the data, each row includes a description which *has* been updated over the years to say what the picture's about.
So the archives - which you can access via
our archive pages or via
our global index - will not include that alternative text tag - going right back through all the images that are in the database.
The code is in PHP, of course ... and the "headline code" that's within the archive generator is as short as:
$ret = preg_replace('/<img\s+(.*?)>/e',
"'<img '.add_alt('\\1').'>'",
$row[entry_text]);
That, though, is just a half of the story - the add_alt function that is called on each match looks something like this:
function add_alt($attribs) {
if (preg_match('!alt=!',$attribs)) {
$rval = $attribs;
} else {
if (preg_match('!src="?http://www.wellho.net/pix/(\S+)!',$attribs,$matches)) {
$name = trim($matches[1],'"');
$rs = @mysql_query ("select filename, descriptor from im_library where filename = \"$name\"");
$dbk = @mysql_fetch_assoc($rs);
$nst = "";
if ($dbk) {$nst = htmlspecialchars($dbk[descriptor]);}
$rval = "$attribs alt=\"$nst\"";
} else {
$rval = $attribs;
}
}
return ($rval);
}
If you're wondering what on earth the picture at teh top of this article is, and you view source on my daily blog ... you won't be given much of a clue. But if you have a look at the archive
here, then the ALT tag will give you, and the search engines, the clues you're likely to be seeking.
Is it still worthwhile, five years on, me writing these tecnical tips? Yes ... I have just been reviewing my user feedback and here are some of the recent unedited comments made:
REALLY A FANTASTIC ARTICLE
Very good explainaiton. Simple and to the point..
Well,it is working good,Thanks for your great work... Thanks Ramakrishnan
I really got helped. These are pure basics of joining which are base of database.
perfect explanation. I can't believe it's that easy. Thank you!
Thanks a lot for the info.Really recommandable job done.
(written 2009-12-28)
Associated topics are indexed under
W504 - Web and Intranet - Not Just Text [3133] An image from a website that occasionally comes out as hyroglyphics - (2011-01-14)
[1806] Dealing with overhead cables in a photograph - (2008-09-21)
[1749] Using server side and client side programming together - (2008-08-11)
[1618] A small picture does not always cut it! - (2008-04-21)
[847] Image maps for navigation - a straightforward example - (2006-08-28)
[665] PHP Image viewing application - (2006-04-01)
[553] Keep that image small - (2006-01-03)
[351] Is photoajustment an addiction? - (2005-06-18)
A301 - Web Application Deployment - XML, DTD, XSLT, XHTML and More [2378] Handling XML in Perl - introduction and early examples - (2009-08-27)
[2246] What difference does using the XHTML standard really make? - (2009-06-18)
[1901] XML, HTML, XHTML and more - (2008-11-23)
[1050] The HTML++ Metalanguage - (2007-01-22)
[653] Easy feed! - (2006-03-21)
Some other Articles
Happy new decade - and course and hotel prices for 2010Rail Campaign - response to core consultationRailway Station Survey - please complete today or tomorrowBookkeepingAdding retrospective ALT attributes to IMGOn a short walk from homeWeb site traffic - real users, or just noise?Perl and the Common Gateway Interface - out of fashion but still very useful?Do not copy and paste code - there are much better waysChristmas Day ...