What is PHP Language? How to start with basic code of PHP?

In this article, you will know all about PHP Language from basic to high. we will tell you all about PHP usage and details. as you know in today’s programming PHP Language comes the most useful language every web designers and web developers need to learn it because without this you can’t develop your website. in online websites, if you see there is PHP coding, the developer developed it with PHP.

PHP is the most popular scripting language. with this language, you can develop your web pages, like what things we can do with PHP? with this language, you can create a login form, registration form, gallery, and many more things. PHP Language is known as a server-side language, it doesn’t execute on your computer without a server.

What is HTML5? With full Definition, Tags, and Example 5 Best HTML Editor in 2019

what PHP stands for:

PHP stands for is “Hypertext Preprocessor“. But that would make it HPP, surely? An alternative explanation is that the initials come from the earliest version of the program, which was called Personal Home Page Tools. so now you get what is it stands for.

So you get a little about PHP, now I told you that PHP is a server-side language it doesn’t run your code without a server. you need to install server on your computer to run your code, don’t worry I will tell you how to get a server on your computer.

For windows users, we have WAMP server to install on Windows PC. and for MacOS users we have XAMP server to install on your PC. but I will tell you about WAMP server so let’s install wamp on your computer you can download wamp from this link download Wampserver 64bit for Windows PC   download Wampserver 32bit for Windows PC

How to install WAMPServer on PC

  • Double click on the downloaded file and just follow the instructions. Everything is automatic. The WampServer package is delivered with the latest releases of Apache, MySQL, and PHP.
  • Once WampServer is installed, you can manually add additional Apache, Php or MySql (only VC9, VC10, and VC11 compiled) versions.
  • Each release of Apache, MySQL, and PHP has its own settings and its own files (data for MySQL).

select language and click ok

accept the agreement and click on next button

Click on next button

set the installation folder on your PC and click next button

now your installation is ready to install so click on install button to install wamp

now you install Wampserver successfully on your computer.

Using Wampserver

  • go to your local disk c:// and open wamp folder
  • The “www” directory will be automatically created (usually c:\wamp\www)
  • Create a subdirectory in “www” and put your PHP files inside.
  • Click on the “localhost” link in the WampSever menu or open your browser and go to the URL: http://localhost

so now you created your folder and PHP file so now you need to open wamp.

Launching your first PHP scripts

Suppose you have created a PHP script called index.php. and you want to open it on the browser to open your browser and type

http://localhost/foldername/index.php

don’t type like this because localhost find www so you don’t need to type in URL

http://localhost/www/foldername/index.php

now your folder and PHP file is ready and Wampserver is also ready so let’s start php coding.

before coding, I should tell you about the variable.

What is Bootstrap? Learn From Basic with Examples What is CSS? Cascading StyleSheet With Full Details and Examples

What is a Variable?

Variable is just storage you put the value inside it and store it. as you store number and text. variable take space in memory each variable have it’s own space that further, we can do anything with it. now I give you example you will get more,

for example,

we have 2 variable by the name of a and b.

$a = 10;

a is variable name after variable name use equal sign (=) and put the value of a that I give 10 after value put a semicolon at the last. don’t forget semicolon is must to put at the last. one thing more variable can only be text and number nothing else. and with the variable name put dollar sign it is just because it modifies variable.

$b = 20;

here is the same b is a variable name and after that use equal sign and its value.

so now we need one variable more to put both variables inside it like.

$c = $a + $b;

so the answer is 30. if we sum $a and $b the result will be 30 because value of $a is 10 and value of $b is 20 so the value of $c will be 30.

Let’s do it practice:

<!DOCTYPE html>
<html lang=”en”>
<head>
<title>First PHP Code</title>
</head>
<body>
<?php
$a = 10;
$b = 20;
$c = $a + $b;
echo $c;
?>
</body>
</html>
here is the result on browser
 
number variable
 
now I will show you variable with text.
$a = ‘hello’;
as I told you before variable name gives the dollar sign and give variable name after that give equal sign then put text between single colon or double colon and at last give semicolon.
$a = ‘hello”;
don’t do like this its wrong.
$a = ‘hello’;
this one is correct.

now let’s do practice.

<!DOCTYPE html>
<html lang=”en”>
<head>
<title>First PHP Code</title>
</head>
<body>
<?php
$a = ‘hello viewer’;
echo $a;
?>
</body>
</html>
here is the result on browser
 
variable text result
PHP start with < then give? and write php and it closes with?  >. and do all your coding inside PHP tag. and in place of print we use echo even, we can use print too but the echo is especially for PHP like.
echo ‘hello viewer’;
 
simply here I will tell you about some of the condition that I will do it with php.

PHP Conditional Logic:

we have many types of Conditional Logic like.

  1. If statements
  2. If else statements
  3. Else if statements
  4. Comparison operators
  5. NOT equal to
  6. Less than and Greater than
  7. The switch statement
  8. logical operators
  9. Boolean Values

Let’s start with if statements.

usually if statements used on the time like for example it gives a command that does this thing or doesn’t do this thing like how now I will give you example

<!DOCTYPE html>
<html lang=”en”>
<head>
<title>First Code</title>
</head>
<body>
<?php
$a = 10;
if($a == 10){
echo ‘correct’;
}
?>
</body>
</html>
here is the result on the browser
 
ans of if statement
so what we did in here we take a variable by the name of $a and we give value 10 to $a. now we give a condition that if $a is equal 10 if($a == 10) then print correct so of course value of $a is 10 so it will print correct in the browser. if our statement is wrong so it will give an error.
 

If else statement.

if, if else and else if are likely similar they all do the same task but there coding is somehow change. now I will give you If else example.

<!DOCTYPE html>
<html lang=”en”>
<head>
<title>First Code</title>
</head>
<body>
<?php
$a = 20;
if($a == 10){
echo ‘correct’;
}else{
echo ‘not correct’;
}
?>
</body>
</html>
so here is the answer on the browser
 
else answer
in here we did that if $a is equal 10 then print correct if $a is not equal 10 so print not correct so now the value of $a is 20 so the answer will be wrong.
now if statement is for this that if this task is correct so run this code if this task is wrong so run this code that what if statement does.

Loop Statement;

now I will show you how to work with loop statement in PHP and how to do a loop with it.

Loop is something that goes around and around until you tell to stop. you also need to tell a loop from where to start and till where to stop and after stopping the loop then what things they should do.

simply you can do code without loop also like $ans = 1+2+3+4 then print $ans; but if there will be 1000 number so can you type it again and again of course no so here you need a loop to run your code till 1000 .

 for example

<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Loop</title>
</head>
<body>
<?php
$a = 1;
$start = 0;
for($start; $start < 11; $start++){
echo$a;
}
?>
</body>
</html>
here we give $a = 1 and $start = 1 so the loop will start from 1 till less than 11 that it will be 10 so it will print 1 eleven time for you here is the result
 
loop answer
so in for loop that we give three tasks, it means that for(initial value; end value; update value).

Initial value.

it means that start loop from initial like start value from 0.

End value.

it means that do loop till the number we give you like I give less than 11 so the loop will end in 10 number.

Update value.

it means that after each number of loop increase the value or increase/sum the number like how the first-time loop run the value is 1 then the second time it increases then the value be 2 then the third time it increases then the value be 3 ….. like this it will do. till the loop end.

so after that, if loop stops so what it should do as I print $a so it will print the value of $a that is 1.

as we have many loops like while loop, do while loop. but I will write an article about that.

Conclusion:

so here I told you all the basic of PHP that a beginner should know and now apply it and do it practically.

if you don’t know which HTML editor to use so here is the link that I published an article about best HTML Editor.

 

 

 

 

 
 
 
 
 
 

 

 

 

 

Leave A Reply

Your email address will not be published.