PHP step by step tutorials Archive
PHP is server side scripting language to develop dynamic websites. PHP developed in 1995 by Rasmus Lerdorf. Early versions PHP was called Personal Home Page but it not seem to be a technical, so PHP rename “Hypertext Preprocessor”, or we can say “Personal Home Page Hypertext Preprocessor”. Advantages of PHP:- Its free. Open source. Easy
Now let’s write and run some basic programs in PHP. Program 1: Program to print “Welcome to php” in PHP. Open notepad++ and write below lines of code: <?php echo “Welcome to php”; ?> Save this program in C://xampp/htdocs/welcome.php Note: if xampp is not installed in C:// then save your program which ever drive xampp
Variable: variable is name of place where computer holds the value temporarily in computer’s memory (RAM), that we can use in our program. In PHP variable is defined with “$” sign. In below program “$a” is a variable contain an integer value “23”, “$b” contain string value “Albert” and $c contain float value “232.44”. Program
Comment code is a line that is not executed as a part of the program. It’s only readable by someone who is editing the code! Comments are useful for Documentation to let other members of your team understand what you were doing in your code. PHP supports three ways of commenting: <?php // This is
Loop is use to do repetitive work until task has not been completed. 1) Understanding “while” Control Structure while is the simplest type of loop in PHP, statement inside the while loop executes until condition in ture. Syntax: while (condition) { statement here will execute when condition is true. } Program 13: Display series 1-10.
Array can hold more than one value at a time. It’s a organized collection of key-value pairs. By default keys of array starts with 0, whoever we can define our own keys also. Syntax: $Ar = Array(emement1, emement2, emement3,…); Program 21: Define and display indexed array. <?php $ar = Array(30,56,amit,ravi); for($i=0; $i < count($ar); $i++)
Form is one of the powerful features of PHP. Below is an example of HTML Form: Program 25: Form example with GET method. <?php echo “hello “.$_GET[‘txtName’]; ?> <html> <body> <form> Name: <input type=”text” name=” txtName”> <br> <input type=”submit”> </form> </body> </html> Note: By default form has get method, so $_GET is use in above
Form validations are used to filter valid data from form. Below are the examples of form validation with regular expression. These are also called server side validations. Program 29: Required field validation. <?php $msg = “”; if(isset($_REQUEST[‘btnSubmit’])) { $name = trim($_REQUEST[‘txtName’]); $email = trim($_REQUEST[‘txtEmail’]); $mobile = trim($_REQUEST[‘txtMobile’]); $message = trim($_REQUEST[‘txtMessage’]); if($name==””) { $msg = $msg
Database is used to store information. In PHP we are using MySql as database server. Below are the steps to use MySql server with PHP: Step 1 : Start MySql from your xampp panel. Step 2 : Open “http://localhost/phpmyadmin/” in browser. Step 3 : Create new database in your localhost server (let’s take database name
This is one of the strong feature of PHP that we can include content of one PHP or HTML file into another PHP file. With this feature we can reduce our codes of line and also avoid repentance of code. This can be done With the help of: include() function require() function include_once() function require_once()