Tech Thought

Tech tips, hints, and general musings. PHP, Perl, Mysql, Javascript, AJAX, JSON, Linux, Mac OSX

Entries for the ‘Development’ Category

How-To: Redirect to different URL using Javascript or META tags

If you need to redirect from one page to another, you can achieve this with either a META tag redirection or Javascript.  See below for an example.  You should provide a manual link as not all browsers support META tags - and javascript won’t work if its been disabled:
<html>
<head>
<title>Move my domain!</title>
<meta http-equiv=”refresh” content=”url=http://www.newdomain.com”>
<script language=”JavaScript”>
function Redirect()
{
window.location [...]

Leave a Comment

WSP Offers Australian Based iPhone Application Development

WSP Online Solutions, a division of WSP Environmental, today launched its Australian based iPhone development services.  iPhone application development is somewhat of a niche market, given that Objective-C (the language used to development native iPhone applications) is not commonly used outside of the Mac community.  As a result, the Australian based iPhone development community is [...]

Leave a Comment

How-To: Create a mysql friendly date with php

This is really simple - and quite useful if you are trying to insert a date into mysql and you can’t use the “now()” mysql command (due to say a timezone difference):
$date = date(”Y-m-d G:i:s”);

Leave a Comment

How-To: Redirect all requests to maintenance page with mod_rewrite

A common requirement when performing maintenance on your website is to redirect all requests to a downtime message. This can be very easily achieve using mod_rewrite and a .htaccess file. Simply create an .htaccess file with the following commands:

RewriteEngine On 

RewriteRule !^site-down\.html$ /site-down.html [L]

This will redirect all requests to the site-down.html file. Once [...]

Leave a Comment

How-To: Embed high-resolution YouTube videos on your site

We had a YouTube video of our product embedded on our website, however it was pretty low-resolution. I wanted to make it display in higher quality, however still making use of YouTube’s servers.
After a little sniffing around, I discovered that you simply add a little bit extra to the embed parameters and it embeds [...]

Comments (1)

How-To: Install Subversion (SVN) 1.5 on Mac OS X

We use CVSDude.org to host all our subversion repositories.  They have recently upgraded to subversion 1.5.0 which is not compatible with 1.4.x clients.  Unfortunately the command line utility that is built into Mac OS X is only at version 1.4.4 on my MacBook Pro - so I needed a way to upgrade to version 1.5.
I’ve [...]

Leave a Comment

How-To: Removing trailing whitespace from a string with php

Need to remove the trailing whitespace characters from a string in php? chomp() is how you do it in Perl, however in PHP it’s just as easy. Simply use rtrim():

// $string = “|my string with trailing whitespace |”
$string = rtrim($string);

// $string = “|my string with trailing whitespace|”

It’s that easy! There is [...]

Leave a Comment

How-To: Check a Reverse DNS Record Lookup (PTR Record) and Solve Email Delivery Issues

More and more mail servers are starting to reject email if your outgoing mail server doesn’t have a reverse DNS record or PTR record. You can check if you have one by issuing the following command:

dig -x 127.0.0.1

Obviously, replace the 127.0.0.1 address with the relevant IP address of your mail server. You should [...]

Leave a Comment

Speeding up prototype.js and scritaculous

We use prototype.js and scriptaculous for a number of our sites and applications - they provide great foundations with which to build advanced javascript applications. However they can be fairly large and take a while to download.
As I’ve previously mentioned on this blog, you can get pre-shrunk versions of both prototype and scriptaculous which [...]

Leave a Comment

How-To Fix: make: yacc: Command not found

I have been getting the following error when trying to compile monit for my CentOS server:
make: *** [y.tab.c] Error 127
To resolve it, I simply installed bison:
yum install bison
Then run configure again:
./configure
make && make install
And that fixed the problem!  Hope that helps someone.

Leave a Comment

How-To: Read an Excel (.xls) file with Perl

I’ve been working on a data import recently that required me to pull in the contents of a folder full of excel documents, all with the same structure containing data that needed to be collated into a single file.  There really isn’t an easy way to read Excel (xls files) in PHP so I’ve reverted [...]

Comments (1)

Testing Different IE Versions in the Same Window: IETester

Finally, a solution to every designer/developer nightmare - developing for different versions of IE.  DebugBar provides you with the rendering and javascript engines of IE8 beta 1, IE7 IE 6 and IE5.5 on Vista and XP, as well as your own version of IE in the same process!
Check it out at here!

Leave a Comment

MagpieRSS strange characters in feed problem

Recently we had a problem with our RSS feed appearing strangely on our homepage.  We were using MagpieRSS to read our RSS feed, however apostrophes and other characters appeared scrambled.
After much reading and googling, it turned out that our page wasn’t using UTF-8 as its encoding method - and our feed was.  So the browser [...]

Leave a Comment

How-To: Setup Mysql Replication - A simple guide

The following is a simple guide to help you setup Mysql replication - a fantastic way to ensure you have an up-to-date backup of your production databases.
This guide only describes a single master-slave relationship, however you can use mysql in various modes which include additional slaves as required.

Comments (1)

How-To: Read an RSS Feed with PHP

An easy way to read an RSS feed with PHP is to use the MagpieRSS library. This provides a simple API to read an RSS feed, and elegantly deal with the issues of timeouts and caching.
It’s as simple as:
require(’rss_fetch.inc’);
$rss = fetch_rss($url);
echo “Site: “, $rss->channel['title'], “<br>
“;
foreach ($rss->items as $item ) {
$title = $item[title];
$url [...]

Leave a Comment

How-To: Determine Real hostname in php

If you need to know the real host name of your server using php, use the following command:
<? echo gethostbyaddr (gethostbyname ($_SERVER["SERVER_NAME"])); ?>
This will return the server’s hostname, not the address that the script is being accessed by. Very useful if you have a script that needs to run on multiple servers.

Leave a Comment

How-To: Parse XML with PHP (SimpleXML)

I’ve been looking for a simple way to convert XML into an array in PHP, like the Perl library XML::Simple does.  The best bet with PHP is SimpleXML, which provides a pretty simple interface for parsing XML in PHP.
Take a simple example XML file:

<list type=’randomlist’>
<item>
<name>Item [...]

Leave a Comment

Hosting Your SVN Repository: CVSDude.com

As a developer, it is really important to have a reliable code repository. I use SVN (subversion) for all my projects and have been looking around for a decent way of outsourcing the repository - I want it accessible to all my staff all the time, it should also be secure and redundant.
We have [...]

Comments (1)

How-To: Insert CSV file into Database Table (csv2sql.com)

I’ve developed a simple online tool that allows you to convert a CSV file into SQL statements that can be inserted into a database table.  It’s a simple process:

Create a CSV file containing your data
The first row of the CSV file should contain column titles which exactly match the fields in your database table
Go to [...]

Leave a Comment

PHP Date in Human Readable Form (Facebook Style)

I like to display dates relative to now, aka Facebook.  So instead of displaying a date in the form 3-2-2008 (which can get confusing if you are in the US/Europe etc with dates being switched) I like to show it as 2 weeks ago as this is far easier to read.
So I came accross the [...]

Leave a Comment