How to Make Rails and PHP Apps Fully UTF-8 Compliant with MySQL

Every web programmer knows that UTF-8 is where it’s at these days. Even if you are coding something for only the US market, you’re still probably going to run into names, addresses, or whatever with accented characters.

Everyone knows that “all you have to do” is make your app speak UTF-8, set the character encoding in your web pages to UTF-8, and set your database encoding and collation to something like utf8_unicode_ci, and you’re off and running… right?

Not quite. You’ve probably run into the situation where you hop into phpMyAdmin and edit some table row, and what to your wondering eyes should appear, but something like this:

Voici un article français.

Well, crap. That’s supposed to be a “ç” in “français”, not an “ç”!

And yet, when you view the web page and edit the content in your app, it looks and works fine! What’s going on here?

It’s really quite simple, and apparently something that no one bothers to mention: you have to tell your app to communicate with the database in UTF-8! Here’s how you do that in PHP and Rails

(more…)

Adding Videos, JavaScript, and Other Goodies to Posts in WordPress MU

Some of you may recall my earlier post Adding JavaScript to WordPress Posts without a Plugin. In that post, I talked about how to add JavaScript for, say, embedding a video without having WordPress “sanitize” your code… and without any plugins!

WordPress MU, the version of WordPress that allows multiple blogs to be run under one WP installation, uses a different content sanitizer. In fact, it’s so seriously anal that it blows away not only JavaScript, but all kinds of other HTML tags in your posts that the regular WP leaves untouched! Bad juju.

In the case of WP MU, the best solution that I could find does include a plugin – but you can write it yourself in about 10 seconds. In writing the plugin yourself, you will also know how to maintain it yourself. Even if you don’t know much about PHP, this one’s a piece of cake!

So, here’s how to convince WordPress MU to play nice with the HTML in your posts…

(more…)

How to Fix “Internal Server Error” Problems on Your Web Site

Bad Kitty!So you’re merrily marching along, happy as a clam because you just set up a glorious new web site that uses, say, a PHP-based content management system like Joomla or WordPress running on a Unix or Linux server.

Everything is going well until suddenly, you start to get feedback from users that they can’t access certain pages or actions on your site. Worse yet, some people seem to be completely blocked from your site entirely.

The problem your users are seeing is a 500 Error, aka “Internal Server Error”. Most of the time, for most people, your site works great… But this is becoming a serious issue for some users.

What to do?

(more…)