Tech Thought

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

Entries for January, 2008

Problem Importing CSV files into Mysql Database

Today I spent sometime trying to import data which originated in an Excel File into a table in my Mysql database using the import interface provided by phpMyAdmin.  I kept receiving error messages due to a column mismatch in the first row of the data.  After trying many different solutions, it turned out that the [...]

Leave a Comment

Credit Card Numbers for testing eCommerce Systems

Recently I've been evaluating ecommerce systems for a client.  As a result i've need to test the payment systems for each – however I didn't want to use my own personal credit card when creating orders.  Thankfully, there are test numbers available to facilitate exactly this.  The following is a list of valid example credit [...]

Leave a Comment

Javascript debugging with Firebug

I've recently been developing a new web based application which relies heavily on AJAX and prototype.js.  Unfortunately, developing advanced javascript applications often requires much inserting of manual alerts in lieu of watch variables and proper debugging.  Now, I've started to use Firebug which is an excellent debugging tool for firefox.  It provides a raft of [...]

Comments (1)

Debugging objects in Javascript with prototype.js

Often when coding complex javascript you’ll wish you had the ability to debug objects or arrays that you are working on – much like Data::Dumper in Perl or var_dump in php (see previous posts on these topics). Prototype.js provides an easy way to do this using the .inspect() method for hashes and arrays: var myComplexHash [...]

Leave a Comment

“Foreach” style loop syntax for Perl, Php and Javascript

I am always forgetting the syntax for foreach() loops in javascript. They actually don’t exist (not in their Perl or Php form anyway) and they differ in that they iterate over all the properties of an object, not an array. You can get some unexpected results if you aren’t careful. In perl you do the [...]

Comments (2)

SilverStripe – An excellent Web 2.0 CMS

I’ve been evaluating a number of CMS for a client recently. These include Xoops, Joomla and now SilverStripe . Joomla is great if you have an ‘intranet’ type site you need to build, where you need features such as Document management, News articles and advanced eCommerce functionality. Joomla’s advantage in these cases is its massive [...]

Leave a Comment

Returning an Excel file from a PHP script

I needed to return an Excel file from a PHP script I wrote.  The simplest way to do this is to create a page consisting of a single table and then setting the headers correctly.  Excel will read the HTML table and convert it automatically into an excel spreadsheet – much easier than writing out [...]

Leave a Comment

Mysql: Defaulting a DATE field to current date

I recently came across the Mysql TIMESTAMP field type.  I’ve seen this datatype for years, however have never really used it – until now.  I’ve been looking for a way to set a fields value to the current date/time by default.  You can’t do this with DATETIME field types in mysql, however you can do [...]

Leave a Comment

Problem with PHP json_decode() and prototype.js .toJSON() function

I have been tearing my hair out trying to work out why PHP’s json_decode() function wouldn’t convert a JSON string sent via AJAX using the prototype.js .toJSON() function. I was sending the string: {\”Assembly_ID\”: 1} However json_decode() in php would return NULL. After some fiddling around, I determined that json_decode() doesn’t like the “\” characters. [...]

Comments (4)

Data::Dumper for PHP

Along the same lines of my previous post, I was looking for a PHP equivalent to Data::Dumper for Perl. Php has a builtin function called var_dump() which will give you some fairly ugly output about your array/hash/object, however I was looking for something a little more elegant.Thankfully the folks over at Pear have come up [...]

Comments (1)

Equivalent to Perl’s ‘chop()’ function for php

I’ve been writing Perl code since just after I learned to walk, so I’m always looking for ways to do things in a Perl-ish manner. My latest requirement was an equivalent to the perl chop() command to remove the last character of a string for PHP. After a bit of searching around, it appears the [...]

Leave a Comment

Javascript Regular Expressions

I was attempting to complete a very simply javascript regular expression which removes a few characters from a string: my_field_124 => my_field So i created the following javascript: fieldName.replace (/\_\d+/, ”); alert(fieldName); What I thought would display is the string “my_field”. Instead I kept getting “my_field_1″ returned. The reason for this is that the replace() [...]

Leave a Comment

Gmail Forwarding Delays, Problems when emailing from another Gmail account

I setup auto-forwarding for a client’s Gmail account today and ran into a couple of interesting problems. Firstly, I tested the auto-forwarding function from my own Gmail account, with the forwarding email address set to my own Gmail account. After a number of attempts, i discovered that i wasn’t receiving the forwarded emails. After playing [...]

Comments (32)