PHP and Web Technologies Freak
Quicksort is one of the fastest and simplest sorting algorithms [Hoa 62]. It works recursively by a divide-and-conquer strategy.
The quicksort is considered to be very efficient, with its “divide and conquer” algorithm. This sort starts by dividing the original array into two sections (partitions) based upon the value of the first item in the array. Since our example sorts into descending order, the first section will contain all the elements with values greater than the first item. Read the rest of this entry »
Navigation menus have to be intuitive, precise and easy-to-use. One simple, basic principle, which is common for all kinds of nav bars you would ever want to use for your projects.
You’ll find 50 user-friendly CSS based menu and navigation solutions.
Titles are everywhere. Some people are defined by titles, some people loathe titles, and others like giving titles. Why do we do this? With so much information getting processed by our minds everyday, we need a way to categorize these groups of associated content in a quick referencing way.
This is the same methodology a search engine applies when it crawls a page. When you title a page, you are telling a search engine or user what the page is supposed to be about. We’ve all seen the one sentence summaries of television shows on the T.V. Guide. It allows for quick referencing and decision making by telling us what the show is going to be about.
Read the rest of this entry »
To find duplicate values you need to use the MySQL COUNT() function and then pick out all of the counts that are greater than one.
SELECT VALUE,COUNT(VALUE) AS COUNT FROM test GROUP BY VALUE HAVING (COUNT(VALUE) > 1) ORDER BY COUNT DESC;
Conversely you can also select the rows that only have a single entry. Read the rest of this entry »
Sometimes, especially when moving data from one server to another, you might find that you have encoded your MySQL database incorrectly. This problem with first show itself if you have the database encoded in one charset and your website set to display in another. If this is the case then you will find strange characters appearing in your text, especially when using punctuation marks. If you are unable or unwilling to change the character encoding on the site then you need to change how the data is encoded in the database.
The most common sort of thing you might want to do is change from iso-8859-1 (or windows-1252) to UTF-8. This can be done in one of two ways.
Read the rest of this entry »

Dijkstra’s algorithm, conceived by Dutch computer scientist Edsger Dijkstra in 1959, is a graph search algorithm that solves the single-source shortest path problem for a graph with nonnegative edge path costs, producing a shortest path tree. This algorithm is often used in routing.
Let’s call the node we are starting with an initial node. Let a distance of a node X be the distance from the initial node to it. Dijkstra’s algorithm will assign some initial distance values and will try to improve them step-by-step. Read the rest of this entry »
If you used Facebook on a regularly basis, you’ve probably come across their cool autocomplete method of adding multiple recipients to messages. For those that haven’t seen it, here’s a pic:

Guillermo Rauch set out to build something similar and he did a very good job of mimicking this behavior using MooTools v1.2:
The failing in using the value of $_SERVER['REMOTE_ADDR'] is that if the visitor is using a proxy then you will get the proxy IP address and not the visitors real IP address.
This function works by going through any variables in the $_SERVER array that might exist that would contain information to do with IP addresses. If they are all empty then the function finally looks at $_SERVER['REMOTE_ADDR'] value and returns this as a default.
function getRealIpAddr(){ if ( !empty($_SERVER['HTTP_CLIENT_IP']) ) { //check ip from share internet $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) { //to check ip is pass from proxy $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; }
To run this function just call it.
echo getRealIpAddr();
This function was originally found here.
It is sometimes a good idea to find out where users can come from. When PHP is run the $_SERVER superglobal is always available and if the user has clicked on a link and landed on your page then the HTTP_REFERER value will be set. You can retrieve it like this.
if ( isset($_SERVER[ HTTP_REFERER ]) ) { echo $_SERVER['HTTP_REFERER']; }
Of course you might want to do something useful with this. For example, you might want to know what link a user clicked on when they broke your application.
This simple code example uses a combination of strrchr to find the last occurrence of a string and substr to return part of the string in order to find the file extension for a given filename. This is ideal if you want to quickly find a file extension.
$ext = substr(strrchr($fileName, '.'), 1);
This code can be used in the following way.
$fileName = '\path\to\file\afile.jpg'; $ext = substr(strrchr($fileName, '.'), 1); echo $ext;
The output here is ‘jpg’;