PHP: Convert XML To JSON

XML is a great format for data exchange. But JSON is used more and more for data exchanging and configuration. In my opinion JSON is a great, because it is more lightweight than XML. More and more apis work with JSON today. Recently I had to convert XML To JSON. Nothing special, just a simple XML String. In this article I’ll show you how to do this with only a few lines of code.

Read more

How To Access HTML5 data- Attributes With JavaScript/JQuery

In HTML5 data- Attributes were introduced. They are a big improvement, because they allow you to store information within a HTML tag. They look like this:

<div id="abc" data-listsize="20"></div>

You see, the div tag is extended by a data-listsize attribute, which has the value 20. But how can you access this attributes with JavaScript? In this article I’ll show you both ways – with plain JavaScript and with jQuery.

Read more

PHP: Return An include And Assign It To A Variable

The include statement is a simple way to include PHP code from another file.

The usage is quite simple. Just write something like this:

<?php
include 'a_file.php';

If the file is successfully included it will return a TRUE or 1. If it failes to include the file it will return a FALSE. But sometimes you may need to get the content of an included file in order to store it in an variable. Unfortunately the include statement just returns TRUE or FALSE, as mentioned above.

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

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