[PHP] Get current time in milliseconds

I recently needed to get the current time in milliseconds, of course this can easily be retrieved using microtime() however I needed the entire number in digits, not in decimals with seconds seperately etc. Heres how:

1
2
3
$timeparts = explode(" ",microtime());
$currenttime = bcadd(($timeparts[0]*1000),bcmul($timeparts[1],1000));
echo $currenttime;

NOTE: PHP5 is required for this function due to the improvements with microtime() and the bc math module is also required (as we’re dealing with large numbers, you can check if you have the module in phpinfo).

Bash, Bad Interpreter

I recently came across:

/bin/bash^M: bad interpreter: No such file or directory

When trying to run a bash script that someone else had edited. This most commonly happens on UNIX systems if the file has been edited on MS-DOS or Mac. The cure for this is to run a simple perl script:

1
2
#!/usr/bin/perl -pi
s/\n/\r\n/;

Save as unix2dos.pl, chmod +x unix2dos.pl and then run like:

./unix2dos.pl filetoconvert.txt

Simples!

About Me

Me!

Me!

Hi. I’m Sam Cleaver, a second year student at Coventry University in Electronic Engineering. I’m also a web developer with almost 8 years experience in programming. I can code in HTML, CSS, Javascript, AJAX (jQuery), Perl, PHP, MySQL in addition to server system administration. I used to live in Hemel Hempstead (now mostly Coventry) I went to The Cavendish School where I studied the usual core subjects and in addition to them, German at GCSE level and then I.T and Design & Technology: Product Design at A-Level.

I have been active in the web community for a long time now, most commonly on forums such as NamePros and DevShed where I post problems as well as most commonly answering them ;) . There have been various exciting projects I have worked on over the years, from creating my own content management systems to creating entire websites as Twerq and FetchMP3.

I am a determined individual that very rarely gives up on anything, even when tasks seem almost impossible, *cough* fetchmp3′s flv retrieval system *cough*.  I take a good approach to problem solving and never have a problem trying to take a completely different approach to a problem if it results in a faster resolution. I work well in teams and often find that by delegation and finding peoples strengths and weaknesses a very effective team is not very hard to establish at all no matter what the task ahead is.

In addition to my freelance web developer work and studying at University, I also work at Debenhams providing great customer service to everyone! :-D

Oh and check out the links below for my facebook, last.fm, twitter etc etc!

If you have any questions just leave a comment here or contact me via the contact form here.