Tips for PHP Developers

I have 3 different servers with 3 different environment settings (2 Windows servers and 1 Linux server). So every time I moved my files from 1 server to another, it’s broken because database credentials or file systems are different. Therefore, I come up with the environment check before any next logic is in place.

$env_check = getenv(‘windir’);
This line will output ‘C:\WINDOWS’ if your codes are on Windows server. And empty if it’s on Linux.
Now I can use condition to control the different credentials and different directory based on the environment. If 2 Windows servers have 2 different setting, you may want to use another stable variable to check.

Let’s draw a shape to replace pushpin on Virtual Earth Map.

Let me show you how to draw a shape to replace pushpin on Virtual Earth Map. If you develop a map for marketing/sales analysis by using geo codes and place pin points on a map, you may consider to use your customized points. First, it will represent your business professionally. Second, you can define the size you desire.

Let’s draw together a shape of a blue ball for example. Open Adobe Photoshop software, you can use any size and any shape such as rectangle or square. I will start with a 40×40 image space with a transparent background. This will not cover your map in the back if you save the file in .png or .gif format. If you save the file in .jpg format, the background won’t look cool on a map.

Select ellipse tool and use fixed size of 38×38 to start drawing a blue circle. Remember to check “Anti-alias” checkbox, so the circle will have a sharpened edge. Now, you can modify the layer by double click on layer. Check the Stroke box and select 1px for the border of the blue circle. Then select a darker blue color to draw the border.

To make the ball looks like 3D image, you can add lighting effect to it by the menu Filter->Render->Lighting Effects. Select any direction of light on the object. Now you have a great image but it’s only in .psd format. We got to save it for the web in .png or .gif format. Click on File->Save for Web & Devices. Select GIF or PNG-24 in the preset drop down box. Save the file to the server.

Then you can use the function provided by Microsoft Virtual Earth API to add this image to a map. The sample codes are below:

var image = “<img src=’images/icons/BlueBall.png’ style=’background:transparent;’/>”;

You can download the .png image here:

The screenshot below is one of the applications we built applying Virtual Earth Map. We need to define geo codes longitude and latitude for each property and embed the ball image for each location on the map.

How to view all files in a directory using php.

With PHP version 5.0 and higher, you can apply a function called dir_scan() to return all the filenames in a directory.

$dir    = ‘dir_scan_test/’;
$files1 = scandir($dir);
The list of filenames will be in an array.

With PHP version 4.0 and lower, you have to use opendir($path) function to retrieve a list of files

So, compared to PHP4, applying PHP5 codes will be much cleaner and therefore your scripts will be executed faster.