PHP: Convert An Array To JSON

Sometimes, when programming in PHP, you’ll need to convert an array to JSON. This enables you e.g. to retrieve data serverside through PHP and pass it to the client, which then can process this data with javascript. There are different ways to do that, e.g. via AJAX.
In this article I’ll show you, how easy it is to convert a PHP array into a JSON String.

Read more

JavaScript: Get A Random Item From An Array

In one of my previous posts I’ve shown you how to get a random item from an array in PHP. Well, there is, of course, a way to do this in JavaScript as well. And it’s also very easy. Just declare someting like this:

<script>
var allItems = ['A', 'B', 'C', 1, 2, 3, 4, 5];
</script>

Read more

PHP: How Can I Find Out, Whether A Number Is Odd Or Even With The Modulo Operator?

There is a simple way in PHP to find out, wheather a number is odd or even. All you need is the modulo operator.

What is the modulo operator?

The modulo operator in PHP is represented by an %. With this operator you can determine the rest of an interger division.
Here’s an example:

Read more

HTML Codes For Playing Cards

Would you like to display playing cards symbols like Diamonds, Hearts, Clubs and Spades on your HTML pages? Well, it’s quite simple. Just use the following HTML codes: Symbol   Code HTML Diamonds ♦ &#9830; &diams; Hearts ♥ &#9829; &hearts; Clubs ♣ &#9827; &clubs; Spades ♠ &#9824; &spades; With the playing cards HTML codes you … Read more

3 Great HTML5 Attributes That Simplify Coding

HTML5 offers a lot of new features, which were, in my opinion, long overdue. In this article i will show you three great new HTML5 attributes which will make coding your HTML5 Website easier.

placeholder-Attribute

Do you know this placeholder texts within form fields like e.g. “Enter your email adress here”? Well with HTML5 you can add placeholders quite easily to your form fields. Just add the placeholder attribute to your form tag. No Javascript or other hacks needed anymore.

Read more

How To Convert A Decimal Number To A Binary Number

Converting a decimal number to a binary number is easy. You just have to divide the decimal number by 2. If the division yields an integer, note 0, otherwise 1.
Now take the integer part of the division and divide it again by 2. Here, too, the value 0 or 1 is determined analogously.
This is done until the result of the division is 0.

Here is an example:

Read more