After getting XAMPP setup, and having Apache and MySQL running open your IDE. Notepad will suffice for now and that is what I will use to demonstrate, but in the future Notepad++ is recommended. Open Notepad and enter in the following.

Save it as a test.php to your desktop and make sure you Save as Type: All Files or it will not work.

Then locate your htdocs folder which is at C:\xampp\htdocs supposing you saved it to the default location on the installer. Drag and drop your test.php file from your desktop into this folder.

Then check once more that MySQL and Apache are running if they are, navigate to http://localhost/xampp/htdocs/test.php in your web browser.

You have created your first program! Now we want to make some dynamic content, so reopen the test.php file by right clicking it and selecting Open With->Notepad to edit it with Notepad. Then enter in the following new code.

What “$” denotes is that it is a variable. Unlike JavaScript, Java, or C++ you do not have to declare what variable type it is. So what happened is the variable $randomvariable was given a random value of zero up to ten. In order to print this variable or echo it we had to cancel the quotation marks and put it in the middle. The periods are just there to make it safe and you do not have to worry about them, just know to put them there. Unlike many other languages php has one of the easiest randomization functions, the “rand” function is built in with php and the first number is the minimum, while the second is the maximum. It is separated by a comma as is required by PHP.
Now save it and refresh http://localhost/xampp/htdocs/test.php you should get the following.

You can refresh the page many times and will get different numbers all within the boundaries of 0-10. I know what you are thinking this is all good and fun but what does this all have to do with regular websites they are not just numbers! Oh, but in a way they are! As I said in the first post php is what makes up html. Once again open the file with Notepad and change the file with the following.

This will create an image with a dynamic height.
This ends the second part of the tutorial, the next tutorial will deal with strings and how to make a random string/image show up.
<-[PREVIOUS] [NEXT]->