Archive for March, 2011

17/03/2011

PHP/MySQL dates

I have posted before as to a MySQL date, i.e. Y-m-d can be converted in a previous post here.

I found myself this evening in need of converting UK dates back into the MySQL format.

Now, the strtotime() function requires a MySQL-style date going in, so doesn’t work in the way I needed it to tonight.

Luckily I found the ukstrtotime() function online, which works great:

function ukstrtotime($str) {
return strtotime(preg_replace("/^([0-9]{1,2})[\/\. -]+([0-9]{1,2})[\/\. -]+([0-9]{1,4})/", "\\2/\\1/\\3", $str));
}

This is then used in the following way:

$mysqldate = date('Y-m-d',ukstrtotime($ukdate));

Advertisements
Tags: , , ,
07/03/2011

Display your latest Tweet in PHP

So on my mobile site (http://cyte.co.uk/mobile) I created a button to link to my Twitter and this very blog you are reading. This got me thinking what I could do to keep the content fresh without much effort. As the mobile site only consists of a couple of lines of text anyway, I thought a “Latest Tweet” section would be good – because it would be ever-changing. After a bit of googling I tweaked a few bits of PHP I found to come up with the following:

<?php
$username = "cytedesign";
$feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1";

function parse_feed($feed) {
    $stepOne = explode("", $feed);
    $stepTwo = explode("", $stepOne[1]);
    $tweet = $stepTwo[0];
	$tweet = htmlspecialchars_decode($tweet,ENT_QUOTES);
    return $tweet;
}

$twitterFeed = file_get_contents($feed);
echo('"'.parse_feed($twitterFeed).'"');
?>

I was so pleased with this in fact that I will use it on the full version of the site as well, and file it away for my employers’ website when we start company Tweeting.

Tags: ,
04/03/2011

View html source in the blackerry torch browser

With the browser in landscape mode, call up the keyboard. Press and hold the “!?123” key until the lock icon shows. Then type 3?$4.

02/03/2011

Make your website mobile friendly

With an ever-growing percentage of people with access to mobile web browsers in their pockets, the time is ripe to take steps to optimise your site for mobile users.

I’ll be posting as I go through getting my own site (cyte.co.uk) mobile-ready. The first step is detecting whether your user is viewing your site in a mobile browser.

I accomplished this in just a few minutes with open source php code from detectmobilebrowser.com.

Be careful here. My hosting company want to charge me £3.99 per month for a mobile site, and I also found a few downloadable scripts that wanted payment for commercial use. Right.