Infinite loops

We all know what a loop is: a programming language statement that allows us to repeat the execution of a piece of code until a certain ending condition is met. If the ending condition is never met or it does not exist at all, the loop never ends: that’s an infinite loop (also known as . . . → Read More: Infinite loops

Swapping two variables in PHP

In my last post at some point in the code I had to do a variable swap (to assign the value of the second variable to the first and vice-versa). To do this I used a third temporary variable to hold the content of the first variable so it’s value won’t be lost.

$temp = . . . → Read More: Swapping two variables in PHP

PHP function to generate all permutations

To generate all permutations of a given set means to find all possible ways the elements of the set can be arranged. For example, if the given set is {1, 2, 3} the permutations are:

1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1

The number . . . → Read More: PHP function to generate all permutations

Removing accents from strings in PHP

A simple method for removing accents from strings in PHP:

1 2 $x = strtr($x, "ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ", "SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy");

Polybius cipher

Polybius cipher is a basic form of encryption invented by the Ancient Greek Historian whose name it bears. It is based on fractionating plaintext characters so they can be represented by a smaller set of symbols. In plain English: all the letters of the alphabet are written in a 5×5 square like the one below:

. . . → Read More: Polybius cipher




June 2017
« Jul