ad

Showing posts with label PHP Program. Show all posts
Showing posts with label PHP Program. Show all posts

Saturday, May 25, 2024

PHP using leap year program

 PHP Using leap year program 

PHP using leap year program


                       Leap Year 

1]  leap year is the one  has 366 days in a year.

2] leap year comes after every four years.

3]  leap year is always a multiple of four.

4] For example,1999,2000, 2007,2008,2009,2010, 2020, 2024, etc are leap years.


Q. Leap Year Program php

 Example

<?php
function isLeap($year)
{
    return(date('L',mktime(0,0,1,1, $year))==1);
}
    for($year=1991; $year<2016;$year++)
    {
        if(isLeap($year))
        {
            echo "$year : LEAP YEAR <br>\n";
        }
        else
        {
            echo "$year:Not leap year<br>\n";

        }
    }
?>

Q. leap year program php

    Output :

leap year program php


 Q. leap year program using  form php

    Example


<html>
    <form method="post">
        Enter the Year : <input type ="text"
name="year">
        <input type="submit" name="submit"
value="submit">
</form>
<?php
if($_POST)
{
    $year = $_POST['year'];
    if(!is_numeric($year))
    {
        echo "string not allowed,
Input should be a number";
        return;
    }
    if((0==$year %4 )and(0!=$year % 100)or
(0==$year%400))
    {
        echo "$year this number is a Leap Year";
    }
    else{
        echo "$year  this numberis not
a Leap Year";

    }
}
?>


Q. leap year program using  form php

    Output :



leap year program php

PHP using leap year program


READ MORE :-

php for loop

Alphabet triangle pattern

PHP program using sum of digits

Q. Sum of Digits in php 



 Example :-

<?php
$number =1222;
$sum=0;
$rem=0;
for($i=0;$i<=strlen($number);$i++)
{
    $rem = $number% 10;
    $sum = $sum + $rem;
    $num = $number/10;
}
echo " number is $number = Addition of digits
<br> Answer is $sum";


?>


Sum of Digits in php 

Output:-

sum of digits php program



Q. Sum of digit using form  php

Example :-

<form method="post">
    Enter number
    <input type="number" name="number"><br><br>
    <input type="submit" value="submit">
</form>
<?php
if( $_POST)
{


$number =$_POST['number'];
$sum=0;
$rem=0;
for($i=0; $i<=strlen($number); $i++)
{
    $rem = $number% 10;
    $sum = $sum + $rem;
    $number = $number/10;
}
echo " number is $number Addition of digits
<br> Answer is $sum";
}

?>


Sum of digit using form  php 

Output :-
sum of digits php program

Related Articles:-

php program to print alphabet pattern O

php array

Type of css

Friday, May 24, 2024

armstrong number program in php

Armstrong number

Armstrong number

Armstrong number

 1] one whose value is equal to the sum of the cubes of its digits.

  2]  There are Four 3digit Armstrong number - 153, 370, 370 , 407, 1634, 8208,  etc

Armstrong number program in php

Example :-

<?php
$num=150;
$total=0;
$x=$num;
while($x!=0)
{
    $rem=$x%10;
    $total=$total+$rem*$rem*$rem;
    $x=$x/10;
}
if($num==$total)
{
    echo "Yes it an Armstrong number";
}
else
{
    echo "Not an Armstrong Number";
}
?>

armstrong number program in php

Output :-

armstrong number check

armstrong number program using form php

Example :-



<form method="post">
    Enter number
    <input type="number" name="number"><br><br>
    <input type="submit" value="submit">
</form>
<?php
if($_POST)
{
    $num = $_POST['number'];
    $a=$num;
    $sum=0;
    while($a!= 0)
    {
        $rem = $a%10;
        $sum=$sum+($rem*$rem*$rem);
        $a =$a/10;
        }
        if($num==$sum)
         {
            echo " $num Yes Number is Armstrong Number";
         }
         else
         {
            echo " $num  Not Number is Armstrong Number";

         }
         }
    ?>

armstrong number program using form  php

Output :-

armstrong number check


Related Articles:-

php program to print alphabet pattern P

php program to print alphabet pattern C

PHP Program factorial number program

Factorial number 

Factorial number

Factorial number 


1] Factorial numbers "!" It is indicated by the icon.

2]  means that all negative numbers are less than 
   f or equal to the product of the given positive numbers

factorial number program in php

Example :-

<?php
$number=9;
$factorial=1;
for($a=$number;$a>=1;$a--)
{
    $factorial=$factorial*$a;
}
echo "Factorial of $number is $factorial";
?>

factorial number program in php

Output :-

factorial number check

factorial number using form php

Example :-

<form method="post">
    Enter The Number <br><br>
    <input type="number" name="number"id="number"><br><br>
    <input  type ="submit" name="submit" value="submit">
</form>
<?php
if($_POST){
    $factorial = 1;
    $number= $_POST['number'];
    echo "Factorial of $number;<br><br>";
    for ($i=1;$i<=$number; $i++){
        $factorial=$factorial*$i;      
    }
    echo $factorial;

}
?>

Output :-

factorial number check

Related Articles :-

php program to print alphabet pattern M

file upload html

how to run php program

PHP program palindrome number

 palindrome number in php

 

palindrome number in php

palindrome number  ::-

1] palindrome number is a number which remains same digits reversed.

2] eg ::- number - 24142 is a palindrome number. 

 on reversing same digits .


1) take a number .

 2) Reverse the input digits.

3) compare the two digits.

4) If equal it is digits is palindrome. 


 palindrome number in php

Example ::-

<?php
function palindrome($n){
    $number =$n;
    $sum = 0;
    while(floor($number))
    {
        $rem = $number % 10;
        $sum = $sum * 10+$rem;
        $number = $number/10;

    }
  return $sum;
}
$input= 1235321;
$num= palindrome($input);
if($input==$num){
echo "$input is a palindrome number";
}
else {
    echo "$input is not a palindrome";
   
}


?>

 palindrome number in php 

Output ::- 

·        Palindrome Number use in  form in php

Example :-

<form method="post">
    Enter a number
    <input text="text" name="number">
    <br></br>
    <button type="submit">Check number</button>
</form>
<?php
if($_POST)
{
    $number=$_POST['number'];
    $reverse=strrev($number);
    if($number==$reverse){
        echo"The number  $number is polindrome";
    }
    else{
        echo"The number $number is not a
polindrom";

    }
    }
?>

   Output :-



 Recommended Articles 

Wednesday, May 22, 2024

how to run php program

 How To Run A PHP Code In  XAMPP

how to run php program


How to Install XAMPP ?


 1]   Apachefriends developed XAMPP . 

2] XAMPP available for everyone free of cose,

 3] download XAMPP through the official website

     https://www.apachefriends.org/download.html

  completing the download of the  setup file, than installation process  "select components"             section , select all the required components.

 setup




  ∴ Next, Select the directory where you want the software to be installed.it is recommended that you 
      use default directory "c\xampp" and click on "next " to complete the installation.


How to Start a New PHP Program In XAMPP ?

1]  Before you run or start  writing any program in php ,you start Apache & MYSQL.

2] next starting both servers, you have to write a program in Notepad, visual studio code ...... etc.

3]  next writing it, save that file  Name  as "program.php".

4] Before copy that file program.php to c:/program Files/ XAMPP/htdocs.

5]  open the browser and type http://localhost.

6]  Now run your code in that browser. 

 How to Run  a PHP Code using XAMPP?

 1] Before running a php script, you must know anywhere to write it.  

2]  XAMPP directory, there exists a folder called "htdocs" This is Where all the programs for 
     The web pages will be stored.

3]   Now, run a PHP Script.

1]  Go to "C:\xampp\htdocs" and inside it, create a  folder. lets  call it  "demo" it's considered 
     good practice to create  a new folder for every project you work on. 


2] Inside the demo folder, create a new text file and name it "index.php" and write the following script.

  
<?php
echo " hi";
?>
<?+php
echo "<marquee>learn php language </marquee>" ;
?>


3] Now to see the script  output open the XAMPP  control panel  and start Apache to host the local 
   webserver, where our script will be running.




4] Now navigate to your browser and type in "localhost/demo/" in the address bar to view the 

∴  OUTPUT  :


 Congratulations with this  you have  created a PHP  file and also executed the          program Successfully.


1) Can we run PHP in XAMPP? 

Yes, you can run PHP  in xampp. First start the XAMPP Server create a program  you want to and  run  http://localhost.


2) How do I run my PHP file?

PHP  files are saved in c:/program  files/XAMPP/htdocs.
you have to open it. click on the program, and it will automatically run on localhost.

Sunday, May 5, 2024

php program to check whether a number is positive or negative

Check whether a number 

php program to check whether a number is positive or negative

Q. program to check whether a number is positive or negative or Zero 

Example ::-

<?php

$no=49;
$result=($no>0)? "positive no":"Negative no" ;
echo $result;

?>

 output ::-

positive no 


Q. php program to check whether a number is positive or negative or Zero 

Form.  

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="
width=device-width, initial-scale=1.0">
    <link rel ="stylesheet" href="
css/bootstrap.css">
    <title>Document</title>
</head>
<body class="bg-primary">
<div class="bg-white col-md-4 mx-auto mt-5 p-3">
<h5>positive/negative /zero</h5>
    <form action="accept-posi-nega-no.php"
method="get">
    <label>enter any no</label>    
    <input type="number" name="no" class="
form-control" required>
    <input type="submit" value="check" name="b1"
class="btn-btn-primary mt-2">

    </form>
    <?php
        if(isset($_GET['b1']))
        {
            $number=$_GET['no'];
       
        if($number>0)
        {
            echo"positive no";
        }
        else if ($number<0)
        {
            echo"negative";
        }
        else
        {
            echo "no is zero";
        }
    }


       
    ?>
    </div>
</body>
</html>


 php program to check whether a number is positive or negative or Zero 

Form . 

Output :--


Related post ::::-

javascript do while loop

php course online

forgot password form


Saturday, May 4, 2024

php program check to even or odd number


Even odd Program


php even odd program

php even odd program

Information ::-

1]  Those EVEN Number  - 2,4,6,8,10 etc.
2] those divisible by 2 number .


1] Those ODD Number - 1,3,5,7,9,11 etc.
2]  Not divisible by  2 Number .

PHP Even Odd Program 

Example :-

<?php
$no=100;
if($no%2==0)
{
    echo"$no is even number";
}
else
{
  echo "$no is odd number";
}
?>

php even odd program

Output :-

php even odd program /output

Even odd Program using FORM in php 

Example :-



<form action="evenor-odd-form.php" method="get">
    <input type="number"  name="number" value="number" required>
    <input type="submit" value="show" name="b1">  
</form>
<?php

  if(isset($_GET['b1']))
  {
  /* input  */
  $no =$_GET ['number'];
 

  $result=($no %2==0)? "no even" :"no odd";
  echo "$result";
  }
  ?>


Even odd Program using FORM in php 

Output :-

php even odd program /output



Related Post :-

php else if ladder

line break html

how to create login forms