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

The JSON Format Explained

The JSON format is a very popular format for exchanging data. It is very easy to use. Find out, how to use the JSON format. What is JSON? JSON stands for JavaScript Object Notation. The format is identical to the way, you would create objects in JavaScript. It is a great way to exchange data … 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

PHP: Detect Time Of Last Modification Of A File

Do you need to find out in PHP, when a file was modified? Then you should take a look at the PHP-function filemtime. This function expects a filename as parameter and returns the modification-time of this file.
Here is an example:

< ?php
echo filemtime('anyfile.html');
?>

This PHP-script will output the timestamp of the last modification of the file anyfile.html.
You can also format this by using the date-function:

Read more

Display A HTML-List Horizontally

Normally a HTML-list is displayed vertically, which means that each entry is below the previous entry. But for some reasons you might want to display the list vertically, e.g. for a menubar.
Here is a simple way to do that.

For this example I’ll use the following list:

<ul>
	<li>Item 1</li>
	<li>Item 2</li>
	<li>Item 3</li>
</ul>

The result looks like this:

  • Item 1
  • Item 2
  • Item 3

Now, we add some CSS:

Read more