Thursday 3 August 2017

PHP


PHP:
Open source.
Rasmus Lerdorf released first version of php in 1994.
HyperText Preprocessor.
Server side scripting language used to make web pages interactive.
Extension:
File must be saved with .php extension.
Downloading Notepad++:
Open google and download notepad++
Click on the first link.
 After download 64 bit.
We can see it has been successfully downloaded then right click and click on show in folder.
 We can see in downloads our downloaded notepad++
Right click and open it.
Installing:
Select the language and click ok button.
Click on next to continue.
Click on I Agree button.
It will ask where the folder should be store otherwise browse and click on next.
Click on next to continue.
Select the shortcut button and click on install.
Click on finish button and installation is successfully completed.
After installation we can see notepad++ is opened. 
To run our program we need command prompt and server to run.
Open google and download wampserver which appears in the first link. Click on the first link.
Click on download button.
We can see download will start in 2 seconds.
After completing that we can see it will be automatically downloaded.
Now, click on show in folder button.
We can see in downloads and click on open button.
It will ask select the language and click ok button.
Next, click on accept the agreement button and click on next button.
 Click on next to continue.
Ready to install.
Installation process is going on.
Click on next button to continue.
 Finally click on finish button.
After installing open command prompt and see whether php is running or not we can see in below image but we can see error.
Because we have not set any path.
Setting path:
Open Mypc and open c drive. 
We can see wamp folder.
Open wamp file and open bin.
We can see in bin php. Click on php.
We can see two folders of php open php5.6.25.
We can see in below image this is our .exe file.
Click on it.
 Now copy the path till the opened folder.
Right click on Mypc.
Click on properties.
Left side we can see Advanced system settings click on it. 
 Click on environment variables.
Click on path.
If we are having path no problem otherwise have to create new path. 
Edit the path.
Paste the path and click on ok.
Open command prompt. 
Now check whether the php is running or not.
We can see it is successfully done because we cannot find any errors. 
Hello world program: 
After writing program save with .php extension.
 Open command prompt.
We can see the output. 
echo:
Used for printing the statements. whatever we are writing in double quotes will print on console.
Variables: 
Name of memory location that holds data.
Syntax:
$variablename = value;
$:
Single dollar is a normal variable with var that stores any value like string, integer, float etc.
In php variable start with $ and need not to be declared.
Rules:
Must start with letter or underscore only.
Cant start with numbers and special symbols.
DataTypes:
Control statements:
If statement:
If statement is executed if condition is true.
Syntax:
if(condition) {
//code to be executed;
}
Flow chart:
Eg:


If else:
Executed whether the condition is true or false.
Syntax:
if(condition) {
//code to be executed if true;
}else {
//code to be executed if false;
}
Flow chart:
Eg:


If else if:
Executes different codes for more than two conditions.
Syntax:
if(condition) {
//code to be executed if true;
}elseif {
//code to be executed if true;
}else{
//code to be executed if false;
Eg:
Switch:
Used to execute one statement from multiple conditions.
Syntax:
switch(expression) {
case value1:
//code to be executed
break;
case value2:
//code to be executed
break;
....
default:
//code to be executed if all cases are not matched;
}
Flow chart:

Break:
If we use break inside inner loop it breaks the execution of inner loop.
Syntax:
jump statement;
break;
Flow chart:

Loops:
for loop:
Set of code for the specified number of times.
If number of iterations is known by the user.
Syntax:
for(initialization; condition; increment / decrement) {

//code to be executed
}
Flow chart:
while loop:
Should be used if number of iterations or not known.
Syntax:
while(condition) {
//code to be executed
}
Flow chart:
do-while loop:
Guaranteed to run atleast once.
Executes the code atleast one time always because condition is checked after executing the code.
Syntax:
do {
//code to be executed
}while(condition);
Flowchart:
Programs:
Add two strings:
Partial strings:

We have to start the Apache and port number should be visible to us.
Suppose if we are getting any error like the action is starting and stopping we can go to config there we have to change port numbers.
Find starting point for a string:

Count the number of occurances of a substring:

Read from user input and write to user output:




Read from a file and write to a file:
Reading a file:

Write to a file:





Ravi replace with chandu:
First non repeated character in a string:


 Permutation of a string:




Digit identification if string have any numbers:



First highest repeated character:

Program to print the pattern:


Program to sum a number in given string:



Database:
After extracting files.

Paste in this folder.


Open xampp server.

We can see php notepad.

Now, write a program and save it in c drive then xamp then htdocs folder with .php extension.

 Successfully connection established.