Category Archives: programming

PHP: File Downloads HTTP Headers

In PHP you can provide file downloads by using a PHP page to “pass through” the file. Of course you could just link to the actual file, however this technique means your file can kept outside of your website root. Another advantage is you can integrate this system into a PHP based user/password system easily. [...]

PHP: Get First Index in Associative Array

The other day I was programming in PHP and needed to get the first index in an associative array. There doesn’t appear to be a built in function to deal with this so I wrote my own. PLAIN TEXT PHP: function getArrayFirstIndex($arr) { foreach ($arr as $key => $value) return $key; } Here's a bit [...]

JS: Execute JavaScript on Page Load

Recently I’ve been making an effort to improve my JavaScript skills, I’m not a JavaScript-Jedi yet but I have been picking up a few, tips, tricks and techniques. One thing that I find extremely useful is using an init function to call other functions when the page has loaded. I have been using the nifty [...]

PHP: Swap Variables One Liner

Here's a nifty one liner in PHP which let's you swap 2 variables values. PLAIN TEXT PHP: list($a,$b) = array($b,$a); Much like the PHP XOR swap there's no real reason this is any better than using a temporary variable, but you might be able to impress chicks with it or something. /* Pete Graham */

PHP: Remove Values from Array

If you need to remove elements from an array that have a particular value(s) here’s a neat way of doing it without any looping: PLAIN TEXT PHP: // our initial array $arr = Array("blue", "green", "red", "yellow", "green", "orange", "yellow", "indigo", "red"); print_r($arr);   // remove the elements who's values are yellow or red $arr [...]