Coding with Jesse

How to deliver XHTML 1.1

A while back, one of my first posts was This site is valid XHTML 1.1, where I explained what I had to do to change the markup from XHTML 1.0 to 1.1. However, I guess I was a total liar in saying that's all I had to change. This is because Internet Explorer doesn't support XHTML 1.1.

So, using PHP, I had to deliver alternative markup to Internet Explorer and Firefox (rather, between browsers that don't support XHTML 1.1 and those that do).

Luckily, we don't have to use any complex browser detection. Instead, we can just inspect the HTTP-ACCEPT header. Browsers supporting XHTML 1.1 will have "application/xhtml+xml" in this list, and those that don't won't. Using PHP, I have the following code at the top of every page:

if ($_SERVER['HTTP_ACCEPT'] != null
    && strpos($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml') == false) {
	$xhtmltype = '1.0';
	header("Content-type: text/html; charset=utf-8");
} else {
	$xhtmltype = '1.1';
	header("Content-type: application/xhtml+xml; charset=utf-8");
}

XHTML is actually a subset of XML, and as a result we need to change a few other things. Mainly, the stylesheet is attached as an xml processing instruction at the start of the document instead of in the <head> tag. At the same time, we output the <!DOCTYPE> tag for each version of XHTML.

if ($xhtmltype == '1.1') {
     echo '<'.'?xml version="1.0" encoding="utf-8"?'.'gt;';
     echo '<'.'?xml-stylesheet href="/screen.css" type="text/css"?'.'>';
     echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" ';
     echo '"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
} else {
     echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ';
     echo '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
}

As I mentioned in the previous article, I had to remove the lang attribute from the <html> tag. However, it is required with XHTML 1.0. So, again, we need to deliver two versions:

<html xmlns="http://www.w3.org/1999/xhtml" 
xml:lang="en"<?php if ($xhtmltype == '1.0') echo ' lang="en"'; ?>>

Next, we have to provide a few more tags that are required still for XHTML 1.0 in the <head> tag:

<?php
if ($xhtmltype == '1.0') {
     echo '<link rel="stylesheet" type="text/css" media="screen"';
     echo ' href="screen.css" id="stylesheet"/>';
     echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>';
}
?>

That's it for most web pages. However, I should include the changes I needed to make to deliver Chitika and Adsense ads. For XHTML 1.1 visitors, we put an <object> tag on the page, and the Adsense code in an external HTML document. For XHTML 1.0 visitors, we embed the <script> code like normal. If you want more details and examples, go check out this article.

Well that's about it. I guess the only other thing I need to do differently is be extremely careful the content on the site doesn't break validation. As soon as a closing tag is missing or an & unescaped, Firefox won't render the page, instead reporting an error. This is actually a strong feature of XHTML in my eyes. Being completely unforgiving about invalid pages will improve the quality of the web eventually (once people move away from HTML). Though, of course, there is a tradeoff of actually having to make valid pages 100% of the time :)

Published on December 4th, 2005. © Jesse Skinner

UTF-8 Encoded Dynamic Text in Flash MX

If you are struggling to get UTF-8 characters to show up properly in dynamic text fields in Flash movies, even though you've embedded the fonts, make sure you aren't publishing as Flash 5!

This painful undocumented little thing took me forever to figure out. I followed all the documentation to a tee, and had no success. Then, I tried to implement one of the examples I read. The example wouldn't work with my current publish settings (Flash 5) so I switched to Flash 6. All of a sudden, the characters displayed perfectly. It seems that UTF-8 support wasn't built into Flash 5, so when you publish for Flash 5 compatibility, it just won't work.

If, however, you are publishing with Flash 6 or higher, and you are still having trouble, you will definitely want to check out Unicode in Macromedia Flash MX on Macromedia's website. That page has links to all the relevant documentation, plus links to other Unicode related sites.

Published on December 1st, 2005. © Jesse Skinner

Do It Now

Talk about synchronicities. The day after I linked to some motivation quotes, my favourite blogger, Steve Pavlina, puts up a new article entitled Do It Now. It's 8000 words, so if you have some time now give it a read, or you might want to bookmark it for later. Steve's writing is a pleasure to read, and he written many great points on personal motivation and productivity in the past that he has seemed to incorporate into this article.

It's also worth mentioning that Steve has recently managed to change his sleeping habits and become a polyphasic sleeper. This means he sleeps for 25 minutes every 4 hours (a total of less than 3 hours a day!) If you're at all interested in this, go check out his journal logs and the rest of his website.

[Update: The synchronicities didn't stop there. I just noticed that on Success Begins Today, John updated his earlier motivation post with a followup entitled Success: Just Do It. It must be Determination Week!]

Published on November 29th, 2005. © Jesse Skinner

Hide Firefox Referals From Firefox Users

I'm glad Julian Bez pointed out we don't have to bother Firefox users with Adsense Firefox referals. Just yesterday, Google opened up Firefox referals for International content providers. I immediately added the banner to the Tools page of this site, and to Free Horoscope Daily, but I totally didn't think about showing Firefox users something different. Julian also outlines how to accomplish this easily with PHP. Thanks, Julian.

Published on November 29th, 2005. © Jesse Skinner

Motivation is a Trap

Over on Success Begins Today, John Richardson put up some great Quotations by John Maxwell:

"The whole idea of motivation is a trap. Forget motivation. Just do it. Exercise, lose weight, test your blood sugar, or whatever. Do it without motivation. And then, guess what? After you start doing the thing, that’s when the motivation comes and makes it easy for you to keep on doing it."

"As you begin changing your thinking, start immediately to change your behavior. Begin to act the part of the person you would like to become. Take action on your behavior. Too many people want to feel, then take action. This never works."

This reminds me a lot of the time I was going to university. I'd spend hours searching and reading articles on the Internet about beating procrastination. I was spending so much time trying to figure out how to get the motivation to do the things I wanted to do.

Eventually, I realised the only way to Get Things Done was to just do them! I don't know what other solution I thought I would find.

Nowadays, I love reading all the tips and tricks for Getting Things Done. It seems like everyone is obsessed with productivity and anti-procrastination. But I also worry that people are spending all their time configuring their Hipster PDA or organising emails in Outlook instead of just working on the things that need to get done.

Now, before you cry "Blasphemy!", I think the principals of Getting Things Done are really great. More or less, I've been applying them for many years. Basically, I keep a file, todo.txt, with everything I need to get done. I have one at home and one at work. I separate it into sections like so:

Main Project
============

sub project
- thing to do
    - detail on that thing
        - sub detail
    - another detail
- another thing to do

And if I ever forget what my Next Action is, I just take a look in the file. But I don't feel I need to do a lot of the other things, like reviewing, or some kind of inbox. I guess I'm just not as busy as some people, I usually have a good idea of all the things I have to do without it causing me stress.

Anyway, these quotes make a great point: finding ways to motivate yourself is a waste of time. If you're going to do anything, go do the thing you need to do.

Published on November 28th, 2005. © Jesse Skinner
<< older posts newer posts >> All posts