»
S
I
D
E
B
A
R
«
Rename files in bash
Dec 19th, 2009 by Andrew McCombe

If you ever need to rename a batch of files using a regex or similar you can use the `rename` command:

# Rename .wav to .mp3
rename -v 's/\.wav/\.mp3/g' *
 
# replace all hyphens in jpgs with a space
rename -v 's/-/ /g' *.jpg

PHP number_format gotcha
Dec 19th, 2009 by Andrew McCombe

Be careful when doing any kind of calculations with numbers that have been passed through PHP’s number_format function as they can lead to unexpected results. The problems lie with the thousands separator (or the decimal separator if you use anything other than ‘.’). Here’s an example:

andrew@adele:/$ php -a
Interactive shell
 
php > $number = 1234.56;
php > echo $number;
1234.56
php > $number = number_format($number, 2);
php > echo $number;
1,234.56
php > echo $number * 100;
100
php >

The issue is that the calculation ignores everything after the thousands separator ‘ , ‘.

»  Substance: WordPress   »  Style: Ahren Ahimsa