Wednesday, November 28, 2012

Detecting character encoding in PHP

Dealing with character encoding is never fun. It's easy to know that something has gone wrong when text is displaying as hieroglyphics, but it can be difficult to figure out why.

I found myself in this position trying to fix some Japanese text the other day and wanted to write a short example of  mb_detect_encoding(); before I forget it.

<?php
// a list of possible encodings
$encodings = array('UTF-8','windows-1251','ISO-8859-1','ASCII','JIS','EUC-JP');

$string = "Example text";  // the text you wish to test
$in_encoding = mb_detect_encoding($string, $encodings, true);
echo "Encoding type: ".$in_encoding;
?>

 If you find that your encoding is something other than what you desire, you should check out iconv();

Thursday, November 8, 2012

Speed up your local Drupal development environment

A friend came across an interesting suggestion for speeding up the database interactions on my local development environment on this page: 

http://drupal.org/node/469086

Basically it's just some changes to mysql's my.ini configuration file:

innodb_buffer_pool_size = 1G
innodb_flush_log_at_trx_commit = 2
innodb_thread_concurrency=8
transaction-isolation=READ-COMMITTED


Then restart mysql.

The improvement will probably vary.