Navigation Menu

Approach to PHP Programming



PHP (Hypertext Pre-proccessor) is a server side scripting langauge which basically used to develop web based applications and also allows web developers to create dynamic content which interacts with database.


Environment Setup


Download xampp server from website  https://www.apachefriends.org/






Install the downloaded file.





After installing open the xampp-control and start Apache server.






Writing a First Program

Notepad is the best environment to write program easily and executed through browser.

PHP syntax in Notepad:




Step1: Write a program in notepad.



Step2: Save the file in the following folder.




Step3: Execute the file through browser.



Output:



Creating Variables

We need to create variables in php with a dollar symbol '$'.




Conditional Statements

1. If...else() statement:

Syntax: if  (condition)
                // statements

            else
                // statement




2. if..elseif() statement:

Syntax: if (condition)
                     // statements

            else if (condition)
                     // statement

            else
                    // statements






Looping Statements

1. for() loop:

Syntax:  for (initialisation;condition;increment/decrement)
             {
                  //statements(s);
                   }




2. while() loop:

Syntax: while(<condition>)
             {
                  // statement(s);
             }





3. foreach() loop:

Syntax:  foreach(<condition>)
             {

                  // statement(s);
             }



String Manipulation

1. Printing new line.




2. String Concatenation.





3. Length of string (strlen()):




4. Accessing position from string (strpos()):





5. Getting Substring from string( substr('string','start_index','length_of string').





File Handling in Python

1. Reading a file




Example to parse menu 

1. Input file:




2. Program and output

 











0 comments: