Basic Concept of PHP

basic php programming

PHP is an open-source dynamic software development technology. PHP was invented in 1994 by Rasmos, PHP is generally a Personal Home Page(PHP).

In these posts, we convert the following topics

  1. Introduction to PHP
  2. What is PHP?
  3. The basic requirement to learn PHP
  4. How to run PHP code
  5. What is variable in PHP, how to create PHP
  6. Conditions in PHP
  7. Operator in PHP

Introduction to PHP

PHP is a general definition Hypertext Preprocessor of dynamic web development software.

PHP is a widely used open-source platform. It is a general-purpose programming language used for developing small, large, and very complex software projects.

PHP codes are executed on the server side.

PHP code has its own syntax and semantics.

To write PHP code we always use syntax

 <?PHP ?>

the above code is PHP syntax. To start php we must use <? and when to end php code syntax we use ?>

The code we write on

 <?php ....?> 

Persor operates as PHP syntax

Eg. code that runs Hello World on screen.

<?php
echo "Hellow World ;
 ?>

What is PHP and when do we use it?

As I have described above php was used for developing small to very complex projects based on the scope of the project. On PHP we can use any technology like IA, Robotics, and others.

PHP has its own libraries that are used for development technology.

PHP has different frameworks based on their functionalities and code reusability they are the 7 PHP most known frameworks.

Some list of PHP frameworks are

  1. CodeIgniter
  2. Laravel
  3. Symfony
  4. CakePHP
  5. YII
  6. Phalcon
  7. FuePHP and others.

Basic Requirements Of PHP

To learn PHP as a beginner we have to know the basic concepts of basic computer science, basic programming concepts, and HTML, CSS, JS, and code editor usages.

Understand the fundamentals of writing script codes.

To learn php it does not require a computer science degree or certificate. It only requires a person or a developer who wants to solve problems by using php technology.

We must download technology that is used for PHP development technologies.

How to run PHP code

To run the PHP script our computer has the following setups

  1. Local server (XAMPP or WAMP for Windows, LAMPs for Ubuntu)
  2. PHP
  3. Mysql
  4. Apache

All PHP code has its syntax. PHP syntax is started by

<?php and end by ?>

To run PHP code we must install local server XAMPP or WAMP on your computers

For these tutorials, we have used XAMPP local servers

How to Install XAMPP Server

XAMPP server is a server that is used to run PHP syntax.

Xampp server driver from the following words

X: Cross Platform

A: Appaches

M: Mysql

P: PHP

P: Perl

XAMPP is an open-source software that is used to provide local servers and test and develop websites.

To download and install the XAMPP server follow the following steps.

Step 1. Download the Xampp server from Appaches friends.

Step 2. Install XAMPP server

Step 3: Run the XAMPP server

Step 4: Start Appach and Mysql server on the Xampp server

The above image shows how to xampp server start Apache and MySQL

After starting Apache and MySQL servers must be green color on their names like the above.

Where to write PHP Code?

Xampp software setups have different folders and different functions, for example MySQL folder is used to store information about the MySQL database, PHP folder is also used to store PHP information data.

From those folders we work on the htdocs folder that is used to store our php project and all php codes are run from that folder.

These folders are found in the directory where we have installed our Xampp setups. If we install our Xampp server on the C directory found as follows

C:\xampp\htdocs

the above code shows the direction of where our htdocs folded found.

Let’s start creating the project of php and name it the student information management system represented by Sims

To create a project on php we follow the following steps.

step 1. Open your htdocs folder where it was found. if it is found on C:\xampp\htdocs as these open it

Step 2: Create a folder by your project name as the above example sims

C:\xampp\htdocs\sims

Step 3: On the sims folder create files that have extension .php files

index.php

index = the name of the file

.php = extension of the files

generally all php files must have .php extensions.

index.php

<?php 
echo "Hello Developer"
echo "I am SIMS System"
?>

the above code shows how to create a php file and write it. Echo = means it is a PHP command that is used to display anything on the screen.

What is Data Type In PHP?

The fundamental concept of programming is data type. Data type is an attributes that manipulate what type of data we perform on it.

In PHP data type can be the following

  • Integer
  • Number
  • String
  • Booleans
  • NULL
  • Float Poing
  • Array
  • Object

What is the variable in PHP?

In PHP variable is the command term that is used to store some values as permanent or temporary.

A variable is a memory location that holds data for some purpose.

Variable declared by $ followed by letter, not numbers, and not allow space between any names.

Correct variable names follow.

  1. Start with dollar sign ($)
  2. The dollar sign must followed by a character, not the number
  3. not start with the number
  4. variable name does not have space between them
    • eg $first_Name = Correct Naming
    • $first Name = Incorrect Naming

How to use variables in PHP code?

The variable can store any data type.

Let store string data types on variables

<?php
$first_name="Caalaa";
$last_name="Tola";
echo $first_name. " ".$last_name;
 ?>

On the above we create two variables those are $first_name and $last_name, it values ar assigned to it, after running our code we get the following.

The above image shows after running our codes on PHP

What is an Operator in PHP?

The operator can take one or more values that generate other vlaues.PHP has two types of operators

  1. ArithmeticOperators
  2. Logical Operators

A. Arithmetic Operators

Arithmetic operators are operators that are used to operate

  • sum,
  • subtract,
  • division,
  • modulo, and
  • multiplications operators.
<?php 

$number1=20;
$number2=10;
$sum= $number1 + $number2;
echo "Sum of " . $number1 ."and + " .$number2." =" .$sum;

?>

The result of the above code is 30, It means the sum of value number1 and values of number2.

Remember: On arithmetic operations, the values of two or more variables must have the same data types.

Subctruction and Multiplication of two numbers below

<?php 

$number1=20;
$number2=10;
$sum= $number1 + $number2;
echo "Sum of " . $number1 ." + " .$number2." =" .$sum .'<br>';



$sub= $number1 - $number2;
echo "subtraction of " . $number1 ." + " .$number2." =" .$sub .'<br>';

$mult= $number1 * $number2;
echo "Multiplication of " . $number1 ." + " .$number2." =" .$mult .'<br>';

?>

above images below the results of the Sum, Subtraction, and Multiplication of two numbers.

Summary

In this article, we learned more about PHP for the next post how to work with Conditions on PHP like if, if else, and others.

Rember:

Follow Telegram group: https://t.me/tobcoders

Youtube Channels: https://www.youtube.com/@borufantube

Author: bbnadmin

3 thoughts on “Basic Concept of PHP

Leave a Reply

Your email address will not be published. Required fields are marked *