News & Blog

Using PHP to Capitalize a Word or Sentence

May 15th, 2011 - Posted by Steve Marks to PHP, Web Development.
If you’re the webmaster of a site that gathers user’s information you’ll probably know all too well that user input can be, to put it blutently, a bit sloppy. This isn’t a problem as such, but can look a bit improper when this information is shared or displayed to o...

Converting PHP print_r() Output to a String Variable

April 4th, 2011 - Posted by Steve Marks to PHP, Web Development.
The PHP function print_r() is great at outputting a variable in a human-readable format. What if we don’t want it to print to the screen however and instead, for example, want to include it’s output in an email? The Solution You might be suprised to learn that you don’t n...

JavaScript new Date() Returning NaN in IE or Invalid Date in Safari

February 8th, 2011 - Posted by Steve Marks to Javascript / jQuery, Web Development.
When it comes to programming, working with dates can be tricky. Luckily however most languages have done the hard work already and come with some kind of built-in date functionality to assist us. JavaScript inparticular has lots of useful functions to aid in getting, setting and outputting...

PHP Multipart Email Getting Cut Off

November 12th, 2010 - Posted by Steve Marks to PHP, Web Development.
By sending multipart emails we can send two versions of the same email at the same time; One sexy HTML version containing all the bells and whistles for modern email clients, and a fallback plain text version for older email clients or users who have HTML formatting disabled. Without the u...

Getting the First Word of a String with MySQL

November 10th, 2010 - Posted by Steve Marks to MySQL, Web Development.
I was recently assigned the task of getting the first word from a field in a MySQL table. In my case it was getting the first part of a customers postcode. Following a quick look through the MySQL reference manual I was guided towards the SUBSTRING_INDEX() function. By using this function ...

How to Get the Last Character in a String with PHP

November 7th, 2010 - Posted by Steve Marks to Web Development.
There a number of ways to get the last character in a string by using PHP. The simplest way I find however is to use the substr() function like so: $str = "This is a string"; echo substr($str, -1); The above example would return ‘g’. By passing a negative value as the second pa...

Passing an Optional Variable to a JavaScript Function

October 13th, 2010 - Posted by Steve Marks to Javascript / jQuery, Web Development.
Ever needed to call a function expecting parameters but use the functions default value rather than passing the same value each time? Let me give you an example: function do_something(my_var) { alert(my_var); } do_something(); In doing the above you will get ‘undefined’ output....

JavaScripts replace() Function Only Replacing First Occurrence

October 3rd, 2010 - Posted by Steve Marks to Web Development.
The replace() function in JavaScript is useful for finding a substring within a string and replacing it with a new substring. What the official JavaScript documentation doesn’t state very clearly however is that the function will only replace the first occurrence. But what if we need...