Blake Schwarzenbach is on MySpace
And thereby becomes the only reason I would ever visit that domain (thx arun) #
Blake Schwarzenbach is on MySpace
And thereby becomes the only reason I would ever visit that domain (thx arun) #
Unicode
I’ve been working on a new web project in my 5-9 time that will hopefully make its debut this week. Across the board, I’ve been trying to do this one in “best practices” mode. One of the problems I have run into consistently is handling non-ASCII characters.
This isn’t exactly anything new to web developers, but now that Unicode has crept into each layer of the stack (Good charset/collation support in MySQL 4.1, Unicode-native languages like Ruby, browser support, growth of XML and XHTML) it’s theoretically possible to do Unicode everywhere, from request to output.
So, the data is the same everywhere. Good. The new problem is that each layer of the stack has its own native character set and/or biases for character handling, and the application code needs to respect that to get it all to work.
My app stack for this project is: PHP 5, MySQL 4.1, Smarty 2.6.10, PEAR::DB 1.7.6. If you combine all that with a proper controller class, it’s possible to make this work painlessly. Oh, I’m also using Gordon Luk’s Freetag, which depends on ADOdb.
Here are my comments and tips on each layer of this stack:
// lines 24-28: case 'html': return htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); case 'htmlall': return htmlentities($string, ENT_QUOTES, 'UTF-8');However, this won’t be so useful because PHP’s htmlentities and htmlspecialchars output named character entities, which may invalidate any XML documents without DTDs that you’re generating (named references are not built into XML, and come from the DTD). You need to always use numeric entities. As long as you’re ouputting Unicode, you don’t really need to encode non-special (e.g. <> & ” ‘) characters anyway… So just handle those with your own texturizer, and throw in SmartyPants while you’re at it.
Those are the steps needed to actually make it work. Now, what about painless? Putting ut8_encode/decodes everywhere sucks. The solution is to do it at the framework level.
class Smarty_MySite extends Smarty {
// ...
function assign($tpl_var, $value = null, $encode = true) {
if ($encode && $value != null) {
$value = $this->utf8_encode_array($value);
}
parent::assign($tpl_var, $value);
}
function utf8_encode_array($var) {
if (is_array($var)) {
foreach($var as $key => $value) {
$var[$key] = $this->utf8_encode_array($var[$key]);
}
} else {
$var = utf8_encode($var);
}
return $var;
}
}
As you see the stack running this site isn’t even handling character encoding well (&& in above code). The support is out there, but you have to do a little work at the application level to make it all work.
Curitiba, Brazil
Thanks to progressive urban planning a few decades back and its current social policies, this poor Orlando-sized city is one of the nicest places to live in Brazil #
A contronym is a word that is both an antonym and a homonym
Like the verb dust: both to remove (to dust the house) and to add (to dust crops). Also, I am a total English language geek. #
PHP Bugs: session_start(): Failed to initialize storage module
A wacky PHP session bug from all the way back in 2003 that popped up on my PHP 5 virtual host last night #
RIP Jets to Brazil
I put this sticker on my car about five years ago, just after the Four Cornered Night tour hit Orlando’s Sapphire Supper Club (now called the Social). Looks like it’s about time to scrape it off.
After 2002’s comedown of an album, Perfecting Loneliness, and a three-year hiatus, it’s clear that the Jets are no more. These days Blake Schwarzenbach attends Hunter College in NYC, where he also teaches writing to undergrads. Anyone want to apply to Hunter with me so we can have Blake teach us about those “metaphor” things? #
The owner, who lives a floor beneath us, spends every weekend moment atop diverse ladders, cutting branches from the ficus trees that enclose our house. As of now, she’s had enough, and this week a crew came and cut every branch off the trees. They’re barren, like winter, except there is no winter here. As they worked—standing in the trees that they were cutting down, swinging live chainsaws one-handed—a fine blanket of sawdust covered our house, and it was kind of like a first snow, but only for us. Susan thought it smelled like new wood, but when I woke up this morning I was overpowered by the smell of sunshine and gasoline. #
A new album from Sony BMG uses an exploitable rootkit as part of its DRM
Amazing forensic work here. See also the pissing match between Sony and Apple over iPods. #