Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Adding retrospective ALT attributes to IMG

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 as below, or enter http://melksh.am/nnnn for individual articles
W504 - Web and Intranet - Not Just Text
  [351] Is photoajustment an addiction? - (2005-06-18)
  [553] Keep that image small - (2006-01-03)
  [665] PHP Image viewing application - (2006-04-01)
  [847] Image maps for navigation - a straightforward example - (2006-08-28)
  [1618] A small picture does not always cut it! - (2008-04-21)
  [1749] Using server side and client side programming together - (2008-08-11)
  [1806] Dealing with overhead cables in a photograph - (2008-09-21)
  [3133] An image from a website that occasionally comes out as hyroglyphics - (2011-01-14)

A301 - Web Application Deployment - XML, DTD, XSLT, XHTML and More
  [653] Easy feed! - (2006-03-21)
  [1050] The HTML++ Metalanguage - (2007-01-22)
  [1901] XML, HTML, XHTML and more - (2008-11-23)
  [2246] What difference does using the XHTML standard really make? - (2009-06-18)
  [2378] Handling XML in Perl - introduction and early examples - (2009-08-27)


Back to
On a short walk from home
Previous and next
or
Horse's mouth home
Forward to
Bookkeeping
Some other Articles
Happy new decade - and course and hotel prices for 2010
Rail Campaign - response to core consultation
Railway Station Survey - please complete today or tomorrow
Bookkeeping
Adding retrospective ALT attributes to IMG
On a short walk from home
Web 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 ways
Christmas Day ...
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/2554_.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb