php tutorials Archives - LoudProgrammer

Tag: php tutorials

PHP Tutorials – How To Declare Variables in PHP

PHP, Tutorials
Variables are like containers for storing information. In PHP a variable is declared by prepending a dollar ($) to the variable name. Unlike other programming languages, PHP has no command for declaring a variable - the variable is created the moment you first assign a value to it. A variable name must either begin with a letter or the underscore character but it cannot start with a number. Besides, a variable name can only contain alphanumeric characters and the underscore. In the example below we are going to declare a variable to store the name of country of a famous football star. $country = "Brazil"; Declaring a variable is a statement in PHP and so we have to terminate it with a semicolon.

PHP Tutorials – Case Sensitivity in PHP

PHP, Tutorials
In PHP, key words are case insensitive whereas variable names are case sensitive. Create an empty text file in your server root directory and save it as casesensitivity.php  and then include the following code in it. <!DOCTYPE html> <head> <title>Case Sensitivity </title> </head> <body> <?php ?> </body> </html> Key words like echo  that represents a function that prints a text string to the browser are case insensitive. This means that you can use them in either upper case or lower case or a mix of both and the outcome of the statement would be the same. In the example below, we use the echo statement in different cases to print out a text string to the browser and the output is the same. <!D...

PHP Tutorials – How to Include Comments in PHP

PHP, Tutorials
A comment is a line of code that is not supposed to be executed as part of the program. You can use a comment to show others what you are doing or to reminder yourself of what you did. A common occurrence is where a programmer comes to look at the code they wrote on year or so down the line and they have to re-figure out what they were thinking when they wrote the code. A comment can remind you of what you were thinking. In PHP there are a couple of ways through which you can include comments in your code. Create an empty text file document and save it in your local computer using the name comments.php  and include the code below. <!DOCTYPE html> <head> <title>PHP Comments </title> </head> <body> <?php ?> &l...

PHP Tutorials – PHP Syntax

PHP, Tutorials
PHP scripts can be placed anywhere inside an HTML document. You can place them at the beginning of your HTML, inside the HTML tags or at the end of the HTML document. In this tutorial we are going to write a simple script that is going to print an "Hello World!" string to the browser to demonstrate the syntax of PHP code. You can use any text editor of your choice to write and edit PHP code. Create a new text document file and save it in your local computer htdocs folder as helloword.php . All PHP scripts must have a file extension of .php in order to executed by the server. After creating the file open it in your text editor of choice and type in the following code: <html> <head> <title>Hello World</title> </head> <body> ...