Let me teach about PHP in easy steps. First of let me explain what is Programing Language.
“ A Programing language is artificial language used to express computer that can be performed with a machine, particularly Computer.”
- PHP is recursive acronym stands for Personal Home Page, it is now said to stand for PHP: Hypertext Preprocessor
- PHP Is used for developing 3 types of applications
- Command Line scripting
- Desktop (or) GUI
- Web Applications
- The main purpose of introducing PHP is to develop Web applications.
- PHP programs saved with an extension of .PHP
- Actually all the web applications runs in an request and respond mechanism (or) client server mechanism.
- The Programs which present in the client machine are sending requests to the server and getting response from server is called client side programs.
examples: Firefox, Chrome, Internet explorer
- All the PHP programs gets executed in server and will give a response back to the client (Browser) in pure HTM format.
- Every PHP program contains HTML Tags plain text and PHP scripts.
- A web server is an application running in the server machine.
- PHP programs can be Placed in most of web servers.
Example: IIS, Apache, NGINX
- PHP can run almost any Database.
- PHP is platform independent.
- At the time of PHP script execution in webserver the PHP script converts into “opcode” (Operational code) and send it to interpreter.
- The PHP interpreter is ZEND it is also called PHP parser.
- This Interpreter converts the “opcode” to HTML.
- For more details about History Click here for Wikipedia.
- On Next Class we will discuss about Instalation of PHP.
If we want work with PHP we need following products in our system .
- Database server
- mail Server
- FTP client (Used to upload and download the content to the server)
- A tool for remote Database administration.
The following installers can be used to install all the above products in our system.
- WAMP (WINDOWS, APACHE, MYSQL, PHP )
- LAMP (LINUX, APACHE, MYSQL, PHP)
- MAMP (MACINTOSH, APACHE, PHP)
- XAMPP ( X PLATFORM, APACHE, MYSQL, PHP)
The above listed are different installers different operating systems.
in our case we are selecting XAMPP in this X means any operating system. (i am using windows operating system)
To download go the following URL
and select the installer, by the time of publishing the XAMPP version is 1.8.0
Double click on Downloaded file
Select language Press OK
Select the installation Folder, by default it will create a folder “XAMPP” in your operating system drive as shown above
In the next screen it will shows the options as shown like above
- Create desktop Icon (it is recommended )
- Create Apache Friends XAMPP folder in Start menu (It is also recommended )
- Next service section (SERVICE SECTION) If you select any one of them they will start automatically at the time of windows boot it is not preferable better don’t select
- Press Install
Now the XAMPP is going to install. it will take little time as per your system environment.
After the Installation complete XAMPP will ask for to start the Control Panel
Press yes you will get screen like above.
Ok Guys now the XAMPP has installed successfully on your system. to check this
start the APACHE server by clicking on the “Start” button shown in the below image
Now go to your browser and type as below
now you will get the XAMPP default page.
OK GUYS IT WAS WORKING.
If you have problem to start the apache server
Check your System has Skype, Teamviewer, Oracle, or any testing tool softwares , if you found any softwares try to uninstall those
because apache by default runs in in port 80, i want to change it to 8082
If you dont want to uninstall and the softwares then change the port number for apache.
to do this follow this simple steps
Open c:\xampp\apache\conf\ open “httpd.conf” file with text editor (notepad)
search for the word which mentioned “Listen :80”
change the “listen 80” to another number Like “listen:8082”
and also change the “ServerName localhost:80″ to “ServerName localhost:8082”
now save the “httpd.conf” file and restart the apache server
go to your web browser type “localhost:8082”
now you will get XAMPP page it will ask for language selection
select your language and you will get xampp page it will shows the xampp version, PHP version , … it was installed
Everybody knows how the Statement works in programing languages as PHP developed from C language lets directly go for sample programs.
We have 4 Conditional Statement in PHP they are
- Switch statement
- IF statement
- Simple If
- IF – else
- IF – elseIF – else
- Nested IF
output will be
Control statements (or) Loops
- while loop
- do while loop
- for loop
- for each loop
Write a program for to display the first 10 natural numbers ?
echo “The first 10 natural numbers are”.”<br>”;
The first 10 natural numbers are
and now just check the below program what will be the out put.
predict what will be the output of the Program ????
Output will be
- Write a program to to display first 10 even numbers ?
- Write a program to to display the multiplication table as shown below ?
5 * 1 = 55 * 2 = 10
5 * 10 = 50
- Write a program to to display odd numbers between x and y ?
- Write a program to to display to display reverse of a number ?
ex: if we taken input “1234” the out has to be “4321”
- Write a program to to display numbers in words ?
ex: if we taken number as “1234” the out has to be “ one two three four”
- A variable which is specified in a function is known as local variable.
- local variable is accessible only with in the function where it was declared.
- the life time of a local variable is with in the function.
- A variable which is specified outside of a function is known as global variable.
- Global variable can be accessed anywhere in the program.
It was an built in multi dimension array in php that stores GETDATA,POSTDATA, cookies, uploader files, error messages occurred in execution and also stores global variables.
The variables present inside $_GLOBAL is called global variables.
Global is keyword of php used for declaring a global variable , a variable declared by using keyword global cant be initialized.
PHP 5 introduces abstract classes and methods. It is not allowed to create an instance of a class that has been defined as abstract. Any class that contains at least one abstract method must also be abstract. Methods defined as abstract simply declare the method’s signature they cannot define the implementation.
When inheriting from an abstract class, all methods marked abstract in the parent’s class declaration must be defined by the child; additionally, these methods must be defined with the same (or a less restricted) visibility. For example, if the abstract method is defined as protected, the function implementation must be defined as either protected or public, but not private.
abstract class AbsClass
echo "Sum = ".($x+$y)."<br>";
abstract function subNum($x=0,$y=0);
class AbsImpl extends AbsClass
echo "Diff = ".($x-$y);
Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled.
Interfaces are defined using the interface keyword, in the same way as a standard class, but without any of the methods having their contents defined.
All methods declared in an interface must be public, this is the nature of an interface.
To implement an interface, the implements operator is used. All methods in the interface must be implemented within a class; failure to do so will result in a fatal error. Classes may implement more than one interface if desired by separating each interface with a comma.
we have a lot of php predefined constants for string handling. lets have a look on few of them
this function was used to find the length of the string.
Syntax: strlen(variable name)
used to replace a part of string with another string.
Syntax: str_replace(search,replace,[number of replaces])
It was same as str_replace but it was case sensitive.
Syntax: str_replace(search,replace,[number of replaces])
it was used to remove the empty space on both sides of a string
Syntax: trim(variable name)
It is used to reverse the string
Syntax: strrev(variable name)
it is used to search the first occurrence of string inside another string.
Syntax: strstr(search, replace)
same as strstr() but it was case sensitive.
Syntax: strstr(search, replace)
Used to add line breaks (<br>) inside a string in place of \n or \r
used to split the string into an array
Syntax: str-split(string [,length])
lenghth is an optional, each character is stored as an array element default is 1.
used to collecting a part of String.
syntax: substr(string, start index,[length])
for count occurrence of substring in main string
syntax: str_count(string,substring,[start position],[length])
- used to repeating a string number of times.
syntax: str-repeat(string, repeat count)
convert the string into lower case of alphabet.
convert the string into upper case of alphabet.
it was used to case insensitive comparison. this function returns “0” if both strings are equal otherwise it will return the numerical difference between first non matching characters.
The value wil be +ve or -ve
It was same as strcasecmp but it was case sensitive.
it will return 0 if both are equal
it will return 1 if string1>string2
it will return -1 if string1<string2
it was used to add extra padding with specified length to the string.
Syntax: str_pad(string,length,[pad string][pad_type])
where PAD_TYPE is a constant of php it will be either of the php
$str=" sunil \n kumar";
echo str_repeat($x, 10)."<br>";
echo strcmp("Sunil", "sunil")."<br>";
echo strcasecmp("Aunil", "Cunil")."<br>";
more string functions…