This tutorial helps you to create your first PHP page. Let’s start with some theory.
What is PHP?
PHP comes from Hypertext Preprocessor and it’s a scripting language used in web programming for creating dynamically pages. Why PHP? It’s powerful programming language that can work very good in small web applications as in large ones. Combined with a well optimized mySQL database, Ajax and maybe a framework can produce outstanding results. To start writing PHP code you will need the following:
- a text editor – e.g: Notepad++
- apache
- also if you work with database I like mySQL.
You can install your software very easily. In Windows just download XAMPP and start it. All your web files must be in htdocs directory. I am using Ubuntu so I’ve installed a LAMP. I do not recommend using phpmyadmin if you are beginner with SQL language because it’s better to use learn the queries by yourself and only after that use a software that makes your life easier.
Let’s write some code.
TASK: Write a PHP page that displays current date, date that will be two weeks from now, and writes them into a file.
We will use date, mktime and fwrite functions from PHP.
You can check them here:
http://php.net/manual/en/function.mktime.php
http://php.net/manual/en/function.date.php
http://php.net/manual/en/function.fwrite.php
Ok, now let’s get into the code:
$variable = this is how you declare a variable in php. There we are keeping the date. As you can see you don’t have to declare the type as in Java, C etc. As you can see we are adding 14 days more to the new date.
echo $variable it’s a raw printing solution. With fopen we are opening the file for writing (see “w”) and we write our variables.
I hope you enjoy this very, I repeat, very basic tutorial in PHP.
Leave a Reply