Php

 1.prime


 <html>

    <style>
        body{
            background-color: lightblue;
       
        }
    </style>
<?php
function isPrime($n)
{
    if($n <=1)
        return false;
    for($i = 2; $i <= sqrt($n); $i++)
    {
        if($n % $i == 0)
            return false;
    }
    return true;
}

$start = 3;
$end = 20;
$count = 0;

for($i = $start; $i<=$end;$i++)
{
    if(isPrime($i))
    {
        echo "$i \t";
        $count++;
    }
}

echo " <br>The Total number of Prime numbers are = $count";
?>
</html>



2)Messgeg Passing 


 <html>
    <style>
        body{
            background-color:lightblue;
           
        }
    </style>
    <center>
        <form action="p2p.php" method="post">
            Enter the Messege :
            <input type="text" name="msg">
            <br>
            <br>
            <input type="submit" value="Sent Messege">
        </form>
    </center>
 </html>




page 2


<html>
    <style>
        body{
            background-color:lightblue;
            text-align:center;
        }
    </style>
<?php
$messeg = $_POST['msg'];
echo "The sent messeg is : $messeg";
?>
</html>




3)Simple Calculaor



<?php
//write a simple progrmae to implemtn simple calculator
if($_POST)
{
    $ans=0;
    $number1=$_POST['n1'];
    $number2=$_POST['n2'];
    $op=$_POST['submit'];
    if($op == '+')
        $ans=$number1+$number2;
        else if($op == '-')
            $ans=$number1-$number2;
            else if($op == 'x')
                $ans=$number1*$number2;
                else if($op == '/')
                    $ans=$number1/$number2;

}
?>

<html>
    <style>
        body{
            background-color:lightblue;
            font-weight:bolder;
        }
        #f{
            width: 200px;
            border-radius:5px;
        }
        input{
            width:50px;
            border-radius:5px;
        }
       
       
    </style>
    <center>
        <form method="post">
           

           <h1>Simple Calculator</h1>

         

           
                First Number : <input type="text" name="n1" id="f"><br><br>
                Second Number : <input type="text" name="n2" id="f"><br><br>
                <input type="submit" name="submit" value="+">
                <input type="submit" name="submit" value="-">
                <input type="submit" name="submit" value="x">
                <input type="submit" name="submit" value="/"><br><br>

                Result : <input type="text" value="<?php echo $ans ?>" readonly id="f">
     
     

        </form>
    </center>
</html>






4)string functions 



<?php
$str1="First Programming languange is Algorithm for the Analytical Engine";
$str2="first programmer was a woman \t";

echo "<br><br> string 1  :".$str1;
echo "<br><br>  string 2 :".$str2;

echo "<br><br> The Lenght of the string1 is:\t ".strlen($str1);
echo "<br><br> The Total words of the str1 is:\t".str_word_count($str1);
echo "<br><br> The Uppercase Of the string2 is:\t".ucwords($str2);
echo "<br><br> The reverse of the string2 is:\t".strrev($str2);
echo "<br><br> The sub string of the str1 is :\t".substr($str1,1,17);
echo "<br><br> The Repeated str2 is:\t".str_repeat($str2,2);

?>






5)ARRAY FUNTTIONS




<!-- #Writea a php progaram to illustrat built-in arara manipulation function any 5 -->
<html>
   
<?php
$arr=array(10,9,8,7,6,5,4,3,2,1);
echo "<br><br> Original Array is :";
foreach($arr as $x)
    echo "$x ";

echo "<br> <br>The Sum of the Array Element is =>". array_sum($arr);
echo "<br><br> The Minimum Value Element From Array is  =>". min($arr);
echo "<br><br> The Maximum Value Element From Array is  =>". max($arr);

echo "<br><br> The Sorted Array is : =>";
sort($arr);
foreach($arr as $x)
echo "$x ";

echo "<br> <br>The Revers Sorted Array is : =>";
rsort($arr);
foreach($arr as $x)
echo "$x ";

echo "<br><br> After Popped Array is  =>";
array_pop($arr);
foreach($arr as $x)
echo "$x ";

echo "<br><br> After Pushed Elemet Array is  =>";
array_push($arr,100);
foreach($arr as $x)
echo "$x ";
?>
</html>




6)GCD and LCM CALCULTOR


<!-- #write a php programp that accepts two numbers using a web form and calculates greatest common divisor (GCD) and
Least Common Multiople (LCM) of Enterd numbers (use Recursive function) -->


<?php
$gcd ='';
$lcm ='';
if($_POST)
{
    $a = $_POST['n1'];
    $b = $_POST['n2'];
    function GCD($a,$b)
    {
        if($b==0)
        {
            return $a;
        }
        else
        {
            return GCD($b, $a % $b);
        }
    }
$gcd = GCD($a,$b);
$lcm =($a*$b)/$gcd;
}

?>
<html>
<center>
<form method="post">

    <h1>THE GCD AND LCM CALCULATOR</h1><br><br>

    <label for="">Enter the First Number</label>
    <input type="text" name="n1"><br><br>

   
    <label for="">Enter the Second Number</label>
    <input type="text" name="n2"/><br><br>

    <input type="submit" value="submit"><br><br>

    GCD : <input type="text" value="<?php echo $gcd ?>" readonly><br><br>
    LCM : <input type="text" value="<?php echo $lcm ?>" readonly><br><br>

</form>
</center>
</html>









7)Demonstrate constructor and distructor




<!-- #Develope a PHP programe to demontstrate constructors and distructors -->

<?php
class Add
{
    public $a = 0;
    public $b = 0 ;
    function __construct() {
        $this->a = 10;
        $this->b = 20;
    }
    function sum(){
        $sum = $this->a +$this-> b;
        echo "Total = $sum";
    }
    function __destruct(){
        echo "<br> Object is Destroyed";
    }
    $obj->new Add();
    $obj->sum();
    unset($obj);
}




8) time zone



<?php
date_default_timezone_set("Asia/Calcutta");
$hour = date("G");
echo "The current time is (in 24 hour format): " . $hour . "<br>";

if ($hour < "12")
{
    echo "Good morning";
}
else if ($hour >= "12" && $hour < "18")
{
    echo "Good afternoon";
}
else if ($hour >= "18" && $hour <= "21")
{
    echo "Good evening";
}
else if ($hour > "21")
{
    echo "Good night";
}
?>








9. Develop a PHP code to read the values entered into the form using the MySQL database.

<html>

<center>

<form method="post">

Rollno:<input type="text" name="r"/><br><br>

name:<input type="text" name="n"/><br><br>

<input type="submit" value="INSERT"/>

</center>

</html>

<?php

$conn=mysqli_connect("localhost","root","", "bea123"); if(mysqli_connect_error())

die("connection failed");

else

{

echo("connection success");

if(S_POST)

{

Sm-S_POST['r'];

Snm-S POST['n'];

Ssql="insert into student (Rollno, name) values('Srn', 'Snm')";

Sres mysqli_query(Sconn, $sql);

if($res)

echo "<br> data insert successfully";

else

echo "<br> error in insertion";

}

}

?>







4. Develop a PHP program to demonstrate String functions. (any 6).

<?php

echo "Use of String Functions:\n",

$str1"Change Your thoughts and you will change the world!!!"; 5str2 "The first progranimer was women";

echo "The Given strings are:<br>"; echo "stringl is:" Sstri."<br>"; echo "string2 is:" Sstr2."<br><br>";

The PIIP strlen() function returns the length of a string. Slen strlen($str1); echo "The length of stri is: Slen;

The PIIP str_word_count() function counts the number of words in a string.

Sword_count str_word_count($str1); echo "<br>The Total words of strl is:" Sword_count;

//Convert the first character of each word to uppercase. Scapitalize ucwords($str1); echo "<br>The uppercase of each word is:\n" Scapitalize;

//Convert a string to uppercase letters.

Supper strtoupper($str1); echo"<br>The uppercase of string is:\n" Supper,

The PHP strrev() function reverses a string.

Sreverse strrev($str1);

echo "The reverse of string is:<br>". Sreverse;

"Comparing two strings."/Scompare stremp($str1,$str2); echo "<br> The comparision of str1 and str2 is:" Scompare;

//Repeating a string with a specific number of times.

Srepeate str repeat($str1,3);

echo "<br>".$repeate;

SNJPSNS TRUST'S DEGREE COLLEGE NIDASOSHI





Comments

Popular posts from this blog

Abhijit_python

Abhijit HTML