Archive for 2007

geek stuff - handling Microsoft Word text in web development

Tuesday, November 13th, 2007

Note: Please contribute to this code in comments, if you find mistakes or know of improvements.

It's surprising to most people - especially computer programmers, it seems - that the English language actually has more than one kind of single quote and one kind of double quote. In fact, if you go back to single-quote characters in old-school typography, you find: (a) the opening single quote, (b) the closing single quote, (c) the possessive apostrophe, and (d) the contraction apostrophe. "Straight" quotes and apostrophes are a later invention, to reduce the number of keys on a keyboard.

Many modern word processing programs such as Microsoft Word automatically insert these special characters into text while the user is typing. Word calls them "smart quotes," and refers to fancy em dashes and the like as "symbols." These characters are very pretty in printed documents; in web development, however, they're a bit of a nightmare. It's something of a de facto workflow for users to copy Word documents and paste them into forms for blogs, content management systems and the like; smart quotes end up rendering as "question marks," because web browsers don't know what to make of them.

If you're experiencing this problem, you may hope for a nice "character set" solution in a meta tag (charset=xxx). Stop. Seriously. There's no character set at the moment that will both solve this problem and render well in most browsers.

The ideal solution is to convert Word documents into plain text before copying and pasting; unfortunately, this has little to do with how most people work. Therefore, if you're a PHP developer, you might need a function to replace these special characters. There are many proposed functions out there for exactly this task; the one I'm posting here is just the one that works for me.

<?php
function fixSmartQuotes($string){ 
    
$pre chr(226).chr(128);
    
    
$search = array( $pre chr(152),
                    
$pre chr(153),
                    
$pre chr(156),
                    
$pre chr(157),
                    
$pre chr(147),
                    
chr(145), 
                    
chr(146), 
                    
chr(147), 
                    
chr(148), 
                    
chr(150),
                    
chr(151),
                    
chr(130),
                    
chr(133),
                    
chr(152),
                    
chr(154),
                    
chr(160)
                    ); 
 
    
$replace = array( "'",
                             
"'",
                             
'"',
                             
'"',
                             
'-',
                             
"'"
                             
"'"
                             
'"'
                             
'"'
                             
'–',
                             
'-',
                             
"&#8218;",
                             
"&#8230;",
                             
'-',
                             
",
                             
' ' ); 
                    
    return 
str_replace($search$replace$string); 

?>


I'll explain this in detail a little later.



rejoice

Monday, October 22nd, 2007

In the wonder of old songs, ones you've forgotten or written off as dated or trite. How they comfort you in certain lonely moments. How they dig up old wounds and then gently, lovingly, lick them clean.



tears in the batter, venom in the sauce

Sunday, October 14th, 2007

I am beginning to understand cooking as a dark art that can perfect or destroy both diner and cook. As a result, I have come to understand how impure my motives have been, how I have cooked for some to seduce or compel admiration, and how I have waged war on others with what I have made.



geek stuff: IE6 “Page cannot be displayed” fix in PHP

Thursday, September 20th, 2007

If you're working with forms in PHP, and especially if you're working with forms that have multiple steps, you've probably run across the "back button" problem in IE6. Here's what it looks like:

1) you fill out a form and click the "submit" button - this takes you to another page.

2) you click the "back" button.

3) IE6 takes you to an error page that says:

"Page could not be displayed"

and/or:

Warning: Page has Expired
"The page you requested was created using information you submitted in a form. This page is no longer available. As a security precaution, Internet Explorer does not automatically resubmit your information for you. To resubmit your information and view this Web page, click the Refresh button."

The problem is this: you want to be able to return to the previous page without resubmitting form data, AND with the form data still displayed as you've entered it. This, of course, is a caching problem. There are numerous proposed solutions for this online, but surprisingly few of them work well. Here's the one that works for me:

<?php
header
("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0″false);
session_start();
header("Cache-Control: private");
?>




discovered

Monday, September 10th, 2007

Blessings on the forgotten, and the wonderful, and the strange.