From a fresh 64-bit install of Centos 5 or RHEL 5 without Apache, PHP or MySQL packages installed:

Install Apache:

yum install httpd.x86_64 httpd-devel.x86_64

Install the latest PHP & MySQL from Remi:

wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm
yum --enablerepo=remi install php php-xml
yum --enablerepo=remi install mysql-devel.x86_64 mysql-server.x86_64 \
    mysql-libs.x86_64 php-mysql

Start Apache and MySQL and you should be good to go:

/etc/rc.d/init.d/httpd start
/etc/rc.d/init.d/mysqld start

Note, if you already have the packages installed and you only wish to update to the latest versions, replace ‘install’ in the yum command with ‘update’.

If you run any sort of CMS on your website and you often paste content in from word processors, e.g. Microsoft Word, then you’ll probably know how much a pain “smart quotes” (sometimes called “curly quotes”) can be.

There are a number of characters that often get automatically converted from a normal quote into a smart quote when you type it into your word processing software. For example, a normal speech mark (“)  will be converted into a very similar, but slightly prettier speech mark. The same thing can happen with commas, dashes, and a whole load of other characters too.

Why are smart quotes a problem?

These smart quotes aren’t part of all character sets. So for example if you’re outputting a page in ISO-8859-1 then the chances are your fancy smart quotes will appear in the browser as a broken character.

Another problem I’ve come across in the past is when performing database queries. Consider this query:

INSERT INTO mytable SET mycolumn=’That’s a nice curly apostrophe you’ve got there’;

Now assume that the apostrophe characters in the string we’re inserting are not smart quotes. This query is going to fail because they are not escaped. I know they should be escaped at this stage, but for the sake of the example they haven’t been escaped.

Now assume that the quotes are actually smart quotes – the query will be successful because the smart quotes do not need escaped. Great you might think! That makes my query less likely to fail if I forget to escape my string!

Wrong.

For one, you should be escaping the string anyway (ever heard of SQL injection attacks? No, then you should Google it pronto). As you can see, smart quotes can cause many headaches and therefore in my opinion should be avoided online.

As well as breaking in some character sets and potentially upsetting your database, I personally like my quotes to be quotes and my commas to be commas. Also from an aesthetic point of view, I actually prefer normal (dumb?) quotes over their “smart” replacements. If you want to make your text look pretty then do it using CSS.

How I replace smart quotes

When I’m building a CMS in PHP I always include this function on any string being saved to a database that may have been pasted from a word processor.

function cleanupsmartquotes($text){
  $badwordchars=array(
    chr(145),
    chr(146),
    chr(147),
    chr(148),
    chr(151),
    chr(133),
    chr(149),
    chr(160),
    chr(161),
    chr(169),
    chr(171),
    chr(173),
    chr(174),
    chr(187),
    chr(188),
    chr(189),
    chr(190),
    chr(191),
    chr(150)
  );
  $fixedwordchars=array(
    "'",
    "'",
    '"',
    '"',
    '—',
    '...',
    '*',
    ' ',
    '¡',
    '©',
    '«',
    '-',
    '(R)',
    '»',
    '1/4',
    '1/2',
    '3/4',
    '¿',
    '-'
  );
  return str_replace($badwordchars,$fixedwordchars,$text);
}

I don’t claim to have written the function, there are a few variations of it available online, but this version deals with the largest number of smart characters I can find. Not only will it convert smart quotes, but also turn copyright symbols, etc into the html code.

If you’ve got any tips for dealing with the dreaded smart quotes, let me know in the comments.

, , , ,