Posts Tagged ‘php’

Easy update to WordPress 3.0.1

Friday, July 30th, 2010

Today I made an easy upgrade to WordPress 3.0.1, automatic and thanks to my great webhost (swedish webhost Binero.se) I can get around the FTP-account form in WordPress. I just set some constants for method and permissions in wp-config.php:

1
2
3
define( 'FS_METHOD', 'direct' );
define( 'FS_CHMOD_DIR', 0755 );
define( 'FS_CHMOD_FILE', 0644 );

How easy this made my life, since I tend to lot of Worpress blogs. If you want to learn some great configuration tips for your wordpressblog check out this article on digwp, theres a lot to do then just easy updates.

WordPress Random Post Box plugin updated

Wednesday, July 28th, 2010

The WordPress Random Post Box plugin is updated to work in WordPress 3.0. You can download the new version 1.0.3 from the plugin directory.

The problem and solution
It was a simple fix but hard to find. As mentioned by Fabian Anderwald (thanks Fabian) files not loaded within wordpress framework now needs to include the file wp-load.php instead of wp-blog-header.php, a change in WordPress that might be a problem for all integrating WordPress in other applications. This also affected my ajax-call in Random Post Box plugin. So, if you are a developer and run in to the same proble change this:

1
require('./wp-blog-header.php');

To this:

1
require('./wp-load.php');

There was also a warning generated from an array, a bug which also had an easy fix.

The original post about the plugin »

strtolower and encoding

Saturday, July 10th, 2010

A PHP problem that tends to sneak by is the handling of strtolower and encoding. For a while now I have worked on a project that is partially on a Windows-server, with limited control for us. Sometimes there is trouble when you make comparison of textstrings and want to use strtolower. Since “Mattias” and “mattias” is not the same thing you want to make both strings lowercse. But strtolower() don’t want to play with for example swedish chars "å,ä,ö" in UTF-8.

A solution to this problem can be to change the chars to something else, why not htmlentities(). You can for example to this to change the value to lowercase and get around encoding problem:

1
2
3
$value = htmlentities($value, ENT_COMPAT, 'UTF-8');
$value = trim(strtolower($value));
$value = html_entity_decode($value, ENT_COMPAT, 'UTF-8');

Another solutions is to use mb_strtolower() if that function is available (which it isn't on the Windows server in question).