Costa Rica Exploring

If it was a little quiet on this site during September, it was because I was a way for 2+ weeks exploring Costa Rica. I’m back, play catch-up and having fun (digitally) developing, sorting and organizing photos from the trip.

We went to Costa Rica and toured the country with GAP Adventures, and despite a lost iPod, a broken (dSLR) camera and more trouble with Delta Airlines than I currently care to mention.

If you’re looking for an interesting place to visit, Costa Rica is well-worth considering. We visited plenty of unspoiled, “un-commercialized” places and saw many interesting wildlife and nature sights.

Scandinavian Wildlife Park

Back in August we visited one of the lesser known sights in Denmark - the Scandinavian Wildlife Park located in Djus, Jutland. We been passing through the area from time to time on our way to the ferry back to Zealand, but never really knew what kind of place it was.

It turned out to be a quite interesting wildlife park with Polar Bears, Brown Bears, Wolves and other interesting animals. While you can meet too many of them in the wild today (in Denmark at least), it was a great time the few hours it took walking around the park and seeing the animals.

You can see a selection of the images in the Gallery.

Loading data from a file with PHP

In programming languages common tasks should be easy, and surprisingly often I find my self loading data from some source file into a database. With PHP loading a CSV file into the database - or posting the data to an API - is quite easy.

The only trick is to know the functions file_get_contents, split (and possibly list). The routine goes something like this:


<?php
$fileName 
‘rawData.csv’;

$content file_get_contents($fileName); 
$rows split(“n”$content );

foreach ($rows as $row) {
    list(
$item1$item2item3) = split(‘;’$row);
    
    
// Do something interesting…
}

?>


The script gets the contents of file into a variable ($contents). Split the contents into an array ($rows) and the forach loop across each row. The first line of the loop splits the row into three fictitious items and the rest of the loop could do something interesting to the data read from the file.

I usually run scripts like these from the command-line (yes, you can do that with PHP scripts).

PHP: Removing an item from an array

If you have a php array, but need to nuke an item from it, the unset function is just the tool to do that. When iterating through the array after removing the item, you should be slightly careful.

The unset function does remove the item, but it doesn’t “reindex” the array, so you should traverse the array by index-numbers after removing the item. The issue is probably best illustrated by this example:

<?php                                                                                                                      $myArray = Array('item 1''item 2''item 3'); // remove item var_dump($myArray); unset($myArray[1]); var_dump($myArray); // Failing bad loop for ($loop 0$loop count($myArray); $loop++) {         echo $myArray[$loop] . "\n"; } // Good loop foreach ($myArray as $item) {         echo $item "\n"; } ?>

You can dowload the above example code here.

PHP4 - Game over

Yesterday PHP 4.4.9 was released, and today PHP 4 is officially dead. There wil be no more updates.

Don’t worry too much tough. PHP 5 is far superior and there’s absolutely no go reason not to have moved on to PHP 5 long ago.

PHP 4 - It was a nice ride and I’m sure you deserve the rest.