LIVE NEWSROOM · --:-- · May 15, 2026
A LIBRARY FOR SECURITY RESEARCHERS

10+ Basic PHP Programs

Post on X LinkedIn
10+ Basic PHP Programs

Hello everyone welcome again to my new article in which I am going to explain some basic PHP and its programs with their output.

With the help of these PHP programs, you can easily understand the working and syntax of this programming language.

// 01 PHP Programming

PHP (Hypertext Preprocessor) is a programming language that is used for web development. It is a server-side scripting language, which means that it is executed on the server and then results in HTML being sent to the client.

this language is often used to build dynamic web pages. Dynamic web pages are pages that display different content every time they are accessed.

// 02 How to create a PHP server in Linux

For creating its server in Linux you have to follow these steps: –

PHP
  1. Navigate to the directory: – var/www/html/
  2. Create a PHP file in the HTML directory
  3. Write code in that file
  4. Go to your browser
  5. You can access the files in the HTML directory by: – localhost/filename.php

Create a file by following these steps if you are not an administrator: –

  1. Open the terminal and navigate to /home/cipherss/public_html/html/ directory
  2. And then run this command: – sudo touch filename.php

// 03 Basic PHP Programs

  1. Print “HELLO WORLD”
  2. Checking leap year
  3. Print table of number
  4. Print the Fibonacci series of number
  5. Print a Factorial of a number
  6. Check Armstrong number
  7. Check Palindrome number
  8. Print the reverse of the number
  9. Swapping of 2 numbers
  10. Find the area of given 2D shapes

Write a program to print “HELLO WORLD”

<?php
$a = "HELLO WORLD";
echo $a;
?>

//output in browser

HELLO WORLD

Write a program to check leap year

<?ph
$year = 2020;  
 
if($year % 4 == 0)
{
    echo $year .""."is a Leap Year.";    
}
else  
{  
    echo "$year is not a Leap Year.";    
}
?>



//output in browser

2020 is a Leap Year.





Write a program to print a table of 7

<?php    


$a = 7;  
echo "Table of 7 is: <br>";
echo "<br>";
for($i=1; $i<=10; $i++)   
{
    $b = $i*$a;
    echo "$a * $i = $b";   
    echo '<br>';	 
}  



?> 
//output in browser

Table of 7

7 * 1 = 7
7 * 2 = 14
7 * 3 = 21
7 * 4 = 28
7 * 5 = 35
7 * 6 = 42
7 * 7 = 49
7 * 8 = 56
7 * 9 = 63
7 * 10 = 70

Write a program to print the Fibonacci series of number

<?php  
$num = 0;  
$n1 = 0;  
$n2 = 1;  
echo "Fibonacci series for first 8 numbers: -";  
echo "<br>";  
echo $n1.' '.$n2.' ';  
while ($num < 10 )  
{  
    $n3 = $n2 + $n1;  
    echo $n3.' ';  
    $n1 = $n2;  
    $n2 = $n3;  
    $num = $num + 1;  
}
?>   


//output in browser



Fibonacci series for first 8 numbers: -
0 1 1 2 3 5 8 13 21 34 55 89







Write a program to print a Factorial of 5

<?ph
$num = 5;  
$fact = 1;
  
for ($x=$num; $x>=1; $x--)   
{  
    $fact = $fact * $x;  
}  
echo "Factorial of $num is: -" .$fact;  
?>  


//output in browser


Factorial of 5 is: - 120



Write a program to check Armstrong’s number

<?php  
 
$num = 407;  
$sum = 0;  
$i = $num;
 
while($i!=0)  
{  
    $x=$i%10;  
    $sum=$sum+$x*$x*$x;  
    $i=$i/10;  
}
 
if($num==$sum)  
{  
    echo $num." is an Armstrong Number.";  
}  
 
else  
{  
    echo $n." is not an Armstrong Number.";  
}  
?> 



 
 
//output in browser


407 is an Armstrong Number.












.

Write a program to check the Palindrome number

<?php  
 
$num = 12321;  
$i = 0;
$n = $num;
 
while(floor($num))
{  
    $mod = $num%10;
    $i = $i * 10 + $mod;  
    $num = $num/10;
}  
 
if($n==$x)
{  
    echo $n." is a Palindrome number.";  
}
 
else
{  
    echo $n." is not a Palindrome number.";  
}  
?> 





//output in browser


12321 is not a Palindrome number.













.

Write a program to print the reverse of the number

<?php  
$num = 12345;  
$rev = 0;  
while ($num > 1)  
{  
    $rem = $num % 10;  
    $rev = ($rev * 10) + $rem;  
    $num = ($num / 10);   
}  
echo "Reverse number of 12345 is " .$rev;  
?>


//output in browser


Reverse number of 12345 is 54321




Write a program for swapping 2 numbers

Using the third variable

<?php  
$a = 40;  
$b = 50;
  
$c = $a;  
$a = $b;  
$b = $c;
  
echo "After swapping: -<br>";  
echo "a =".$a."  b=".$b;  
?>  


//output in browser


After swapping: -
a = 50 b = 40



Without using a third variable

<?php  
$a = 40;  
$b = 50;  
  
$a = $a + $b;  
$b = $a - $b;  
$a = $a - $b;  

echo "After swapping: <br>";
echo "Value of a: - " .$a ."</br>";  
echo "Value of b: - " .$b ."</br>";  
?>  


//output in browser


After swapping: -
Value of a: - 50
Value of b: - 40



Write a program to find the area of given 2D shapes

Area of circle

<?php  
$r = 2;  
$area = 3.14 * $r * $r;
  
echo "Area of circle is: -" .$area;  
?>  

//output in browser

Area of circle is: - 12.56

Area of rectangle

<?php  
$l = 10;  
$b = 20;  
$area = $l * $b;

echo "Area of rectange is: - " .$area;
?>  

//output in browser

Area of rectangle is: - 200


Area of triangle

<?php  
$l = 10;  
$b = 20;  
$area = 1/2 * $l * $b;

echo "Area of triangle is: - ".$area; 
?>  


//output in browser

Area of triangle is: - 100

Area of square

<?php  
$a = 10;
$area = $a * $a;  

echo "Area of square is: - ".$area;
?>  


//output in browser


Area of square is: - 100

    TE
    Team Ciphers Security

    Independent cybersecurity desk publishing daily threat intel and research since 2021. Practitioners writing for analysts, defenders, and learners. About us →

    Previous Short Report on password attack tools hydra and crunch Next Java Programming Tutorial

    Latest News

    YARA-X 1.16.0: Faster Scans, Panic Fixes, and Neovim LSP Support YARA-X 1.16.0 ships with performance improvements across 10 PRs, constant folding for bitwise ops, configurable mat… Instructure Removed from ShinyHunters' Leak Site as Canvas Breach Deadline Passes Instructure was quietly removed from ShinyHunters' extortion site after the May 12, 2026 deadline — no data dump, n… Costa Rica Joins Have I Been Pwned as the 42nd Government Costa Rica's CSIRT gains free access to Have I Been Pwned's government domain monitoring service, becoming the 42nd… LummaC2 Infostealer Targets US Critical Infrastructure: CISA-FBI Advisory AA25-141B and DOJ Domain Seizures CISA and FBI advisory AA25-141B details LummaC2 MaaS infostealer TTPs targeting critical infrastructure. DOJ seized… MacSync Stealer: Hackers Abuse Google Ads and Claude.ai Chats to Push Mac Malware Russian-speaking attackers combine Google Ads and Claude.ai shared chats in a ClickFix campaign deploying MacSync S… JDownloader Site Hacked, Installers Swapped with Python RAT Malware JDownloader's website was hacked May 6–7, 2026, replacing Windows and Linux installers with a Python-based RAT. Use… Operation HookedWing: 4-Year Phishing Campaign Hits 500+ Organizations Across Aviation, Energy, and Logistics Operation HookedWing has stolen credentials from 500+ organizations in aviation, energy, logistics, and critical in… Twelve Critical vm2 Node.js Vulnerabilities Enable Sandbox Escape and Arbitrary Code Execution A dozen CVEs in the vm2 Node.js sandbox library — including CVSS 10.0 flaws — allow sandbox escape and RCE. Update …
    Scroll to Top