:::: MENU ::::
Browsing posts in: Uncategorized





Importing a CSV UTF-8 – BOM (Byte Order Mark) Microsoft Excel.

Before I start, here is a little credit to @mark_hamstra for putting me on the right track with fixing this issue today.

CSVs

Although CSVs seem like simple files for transferring data and importing into websites, they actually end up being quite complicated when you start to need to convert to UFT-8.

EXCEL

From what I can tell, one of the biggest issues around CSVs originates from Excel. In fact it was only exporting CSV files from Excel that I was having any issues with.

None of the other programs I was using seemed to add a BOM at the start of the file. Numbers, Open Office and Google Sheets all seemed to work fine.

Solution

There are a couple of solutions that I found worked for me.

Solution 1 (courtesy of https://stackoverflow.com/questions/32184933/remove-bom-%C3%AF-from-imported-csv-file )

$file = ‘something.csv';
$content = file_get_contents($file);
var_dump(removeBomUtf8($content));
function removeBomUtf8($s){
   if(substr($s,0,3)==chr(hexdec('EF')).chr(hexdec('BB')).chr(hexdec('BF'))){
      return substr($s,3);
    } else {
      return $s;
    }
}

Solution 2

If you know for a fact that your file always has a BOM, you can simply use an fseek() to skip the first 3 bytes, which is the length of the BOM. This solution works fine, however you need to be completely sure that the csv file always has a BOM. If it doesn’t you will probably run into problems.

$file = fopen(“nam_of_cv.csv”, "r");
fseek($file, 3);

100 Mile Charity Bike Ride

I had a great idea a few months ago. I have always enjoyed cycling and although I have never really taken it particularly seriously the challenge of riding 100 miles has always been something I have been keen to achieve, so with a couple of like minded friends I signed up for the Cambridge 100 bike ride run by Bike Events on the 27th April 2014.

Less than two weeks now until the ride Its suddenly dawned on me – 100 miles is a ridiculously long way! Realistically we hope to average above 15MPH which would still mean 6 or 7 hours sat on a saddle.  Even if I wasn’t having to peddle that is a very long time to be perched on an saddle of a bike which, less face it, is not particularly renowned for its luxury and comfort.

Surely you have been doing some training though? – I hear you cry. Well yes, of course I have – well, sort of. I started a few months back searching for training plans for building up to a 100 mile ride. I was determined to be as prepared for this ride as I could be. I didn’t want to turn up and cough, wheeze and splutter my way around every single mile after all, I wanted to, as far as was possible, enjoy this ride. Most of the plans I found were based on 8  week courses, fairly intensive schedules for people who were reasonably fit ( I felt I qualified in this category).  But being 12 weeks away from the ride and fairly busy with work and other commitments, I didn’t actually start doing any real training until a couple of weeks ago, just 4 weeks until the ride.

So now the panic is setting in and I am trying to get out on the bike whenever I can. I am sure my training is doing some good but I do feel as though I am playing catch up (any ambitions of carefully following a methodical 8 week plan have been long since thrown out of the window).

Last weekend I did my longest ride to date – a 70 mile slog around Bedfordshire villages and boy, it was tough. Everything started well, I swallowed up the first 40 miles like they were never there but after the 50 mile mark my legs were tired and I was ready to call it a day. At 60 miles a bit of cramp kicked in and the final 5 miles were shear agony.  I managed to average what I thought was a respectable 15.9MPH (especially on a blustery day).

So this is set up to be quite a challenge come April 27th. I am riding for Prostate Cancer research so if you would like to sponsor me for this ride then please head over to my Just Giving Page.