Main Content

How did I do THAT?

Archive - Originally posted on "The Horse's Mouth" - 2009-10-26 05:16:35 - Graham Ellis

I had great fun putting together yesterday's blog about My train journey from Melksham, with a whole lot of images in the text rather than real words.


For my first tests, the images sat on the line like this: which starts to look really ugly once you 've added more that a couple of pictures - so I have fine tuned my "img" tags, adding in both align="middle" and "vspace=2" (and, yes, I know ... deprectation warning - should have used style!). I then added alt="what it is text" to provide a backdrop of desciptive text whould people use various browser facilities to read me properly.


But then I also wanted to provide me with a "just show me the friging text" option, so I wrapped my images in PHP tags:
< imagestart("tiny_bristol") ?>Bristol< imageend() ?>
and provided thos extra functions imagestart and imageend:

<?php function imagestart($wot) {
  return (($_REQUEST[txt]=="")?
  "<img src=http://www.wellho.net/pix/$wot.jpg align=middle vspace=2 alt=\""
  :"") ; }
function imageend() {
  return (($_REQUEST[txt]=="")?
  "\">"
  :""); } ?>

i
Notes

1. The reason to use functions should be glaringly obvious - it saves the need to keep repeating a messy piece of code. Write it once, debug it once, and have it used consistently. But why two functions? Ah - that's because I want to keep my ALT text outside the tags so that if I run the PHP function stripslashes on the text, I am left with the keywords correctly. That way, I can help blog feeds and our own other scripts which re-use the blog text or search through it such as this one to index / report the page properly too.

2. The $_REQUEST[txt] control is the quasi-form element that I am using to control whether the text is show in picture or text form. It's defaulting to pictures, but links on via
<a href="?txt=x">[here]</a>
to the plain text version and back via
<a href="?txt=">[here]</a>
to the version with pictures again.

3. In order to keep PHP code in my Movable Type (Moveabletype) database, I added code that uses functions such as ob_get_contents to my templates, and I've also ensured that .html URLs are parsed by the PHP interpretter. For details, see here and here