Tuesday, 11 August 2015

How To Find Armstrong Number In Php

Php program for Armstrong number
Definition: -  Armstrong number is a number which is equal to a Sum of digits raise to the power total number of digits in the number.Here Is PHP program for Armstrong Number In this post we will help you to learn how to find Armstrong number in PHP. To run this program copy paste this code and save it as any name but with ".php" extension.  

<html>
<body bgcolor="#C5FF13">
<title>Php program for armstrong number</title>

 <!-- to test this script type 371 or 407, these are Armstrong numbers -->

 <h2 align="center">Php Program For Armstrong Number</h2>
<h3> Program Bye Helps2code.com</h3>
 <form action="" method="post">
<table border="1" align="center"> <tr> <td>  <input type="text" name="number" placeholder="Enter A Number" /></td></tr>
<tr><td>  <input type="submit"/></td></tr></table>
 </form>

</body>
</html>

<?php

 if( $_POST )
 {
  //get the enter number
  $number = $_POST[ 'number' ];

  //store it in a temp variable
  $temp = $number;
  $sum  = 0;

  //loop till the quotient is 0
  while( $temp != 0 )
  {
   $rem   = $temp % 10; //find reminder
   $sum   = $sum + ( $rem * $rem * $rem ); //cube the reminder and add it to the sum variable till the loop ends
   $temp   = $temp / 10; //find quotient. if 0 then loop again
  }

  //if the entered number and the $sum value matches then it is an ARMSTRONG NUMBER
  if( $number == $sum )
  {
   echo "Armstrong Number";
  }else
  {
   echo "Not an Armstrong Number";
  }
 }

?>

After saving this program open your WAMP Or XAMP Server and run it.
If You find This Program Helpful Leave A Comment And Do Share With Your Friends.
Php Program of Armstrong Number
Php Program of Armstrong Number
Other Php Program For helping You: :)

How To Count Vowel And Consonant In Php

In This Program, we will Find Vowel and Consonant.
"How to count Vowel and Consonant" This is the important program in PHP. Copy this program and save it as any name but with a .php extension, and run it on your WAMP or XAMP server. If You Need Any Help Comment Below.

PHP script vowels from string count number of vowels in php

PHP script to find number of vowels in a string


<html>
<title> Vowels and Consonants Counter</title>
<style>
body {
  font-size:20px;
  font-family:arial;
  color:blue;
  }
</style>


<?php

error_reporting(0);
$values = $_POST['value'];
if(isset($_POST['check'])) {

  if ($values==" ") {
      echo "<script>";
     echo "alert('It Cannot Be Empty!!! Please enter a sentence.');";
     echo "</script>";
     $values=" ";
     $results=" ";
     }
 if ($values != " ") {
   $total_vowels = 0; $total_consonants=0;

      $vowels = Array('a','e','i','o','u','A','E','I','O','U');
      $vowels = Array('a','e','i','o','u','A','E','I','O','U');
      $consonants = Array('b','c','d','f','g','h','j','k','l','m'
                ,'n','p','q','r','s','t','v','w','x','y','z'
                ,'B','C','D','F','G','H','J','K','L','M'
                ,'N','P','Q','R','S','T','V','W','X','Y','Z');

for ($b=0;$b<strlen($values);$b++)
{
    for ($a = 0;$a<10;$a++)
        if ($values[$b] == $vowels[$a])
        {
            $total_vowels++;
            break;
        }

 for ($a = 0;$a<42;$a++)
        if ($values[$b] == $consonants[$a])
        {
            $total_consonants++;
            break;
        }
 }
   $results .=  "==== REPORT ==== ";
   $results .=  "<br><br>";
   $results .= "The sentence is   :=>   " .$values."<br><br><br>";
   $results .= "Total Consonants  :=>  " .$total_consonants."<br>";
   $results .=  "Total Vowels     :=>  " .$total_vowels."<br>";

   }


    }
 


if(isset($_POST['clear'])) {
  $values=" ";
  $results= " ";

}

?>
<body style='background-color: #FF00DD>
<div style='width:800px;margin:auto'>
  <br> <h1 align="center">Vowels and Consonants Counter</h2>
  <br>
<form action="" method="post">
 Enter a Sentence : <input type="text" name="value"    value="<?php echo $values; ?>" autofocus  size=50/>
 <br><br>
   <input type="submit" name="check" value="Find Vowels and Consonants"
  title="Click here to know the number of Vowels and Consonants in a given sentence."/>
  <input type="submit" name="clear" value="Clear"
  title="Click here to clear text box and values on the screen"/>
</form>
<br>
<?php
echo $results;
 ?>
  </body>
</html>

If You Found This Program Helpful Leave A Comment And Do Share With Your Friends.

You May Also Like:-
Palindrome Number In Php
How To Find Armstrong Number In Php

select insert update and delete using php mysql

In This post we will practice how to SELECT INSERT UPDATE and DELETE any data in MySQL using PHP. this is a simple code for this select insert update and delete program. follow the code and if you find any error comment below .

<?php
include('connectivity.php');
error_reporting(1);

$n=$_POST['n'];
$e=$_POST['e'];
$m=$_POST['m'];
$p=$_POST['p'];
$c=$_POST['c'];

if(isset($_POST['insert']))
{

$h=$_POST['c'];
$hobb=implode(" , ",$h);

$pic=$_FILES['file']['name'];


$sql="select email from users where email='$e'";
$r=mysql_query($sql);
$data=mysql_num_rows($r);
if($data==true)
{
echo "<font color='red'>user already exists</font>";
}
else
{
$query ="insert into users values('','$n','$e','$p','$m','$hobb','$pic')";
mysql_query($query);

mkdir("usersdata/$e");
move_uploaded_file($_FILES['file']['tmp_name'],"usersdata/$e/".$_FILES['file']['name']);

echo "your data saved...";
}
}

//update records
if(isset($_POST['update']))
{
mysql_query("update users set name='$n',mobile='$m',pass='$p' where email='$e' ");
echo "records updated";
}

//delete
if(isset($_POST['delete']))
{
mysql_query("delete from users where email='$e' and pass='$p'");
echo "records deleted";
}
//display
if(isset($_POST['display']))
{
}

$sql= mysql_query("select * from users");
echo "<table border='1'>";
echo "<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Password</th>
<th>Mobile</th>
<th>Image</th>
<th>updatation</th>
</tr>";
while($row=mysql_fetch_array($sql))
{
$email=$row['email'];
$picname=$row['pic'];

echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['email']."</td>";
echo "<td>".$row['pass']."</td>";
echo "<td>".$row['mobile']."</td>";
echo "<td><img src='usersdata/$email/$picname' width='100px' height='100px'/></td>";

echo "<td>
<a href='delete.php?uemail=$email'>Delete<a/>&nbsp;&nbsp;
<a href='edit.php?uemail=$email'>Edit<a/>
</td>";
echo "</tr>";
}
echo "</table>";
?>
<form method="post" enctype="multipart/form-data">
<table width="426" border="1">
<tr>
<td width="176">Enter your name </td>
<td width="234"><input type="text" name="n"/></td>
</tr>
<tr>
<td>Enter your Email </td>
<td><input type="email" name="e"/></td>
</tr>
<tr>
<td>Enter your password </td>
<td><input type="password" name="p"/></td>
</tr>

<tr>
<td>Enter your mobile </td>
<td><input type="text" name="m"/></td>
</tr>

<tr>
<td>your hobbies </td>
<td>
cric<input type="checkbox" name="c[]" value="cric"/>
singing<input type="checkbox" name="c[]" value="sing"/>
football<input type="checkbox" name="c[]" value="foot"/>

</td>
</tr>

<tr>
<td>upload your pic </td>
<td><input type="file" name="file"/></td>
</tr>

<tr>

<td colspan="2">

<input type="submit" value="Insert" name="insert"/>
<input type="submit" value="Update" name="update"/>
<input type="submit" value="Delete" name="delete"/>
<input type="submit" value="Display data" name="display"/>
</td>
</tr>
</table>
</form>

If You Find This Program Helpful Leave A Comment And Do Share With Your friends. If You Have Any Query Related To This Program Comment Below. Happy Coding.

You May Also Like: -

Fibonacci Series In Php

Armstrong Number In Php

Palindrome Number In Php

Create A Calculator Using PHP

How To Create a Calculator in Php

In this post we will learn to create a calculator in php with some simple code. To create a calculator you have to follow this code. copy the code in your text editor than customize it with your design.

<?php
if(isset($_POST['disp']))
{
$f=$_POST['f'];
$s=$_POST['s'];
$ch=$_POST['ch'];
switch($ch)
{
case '+':
$res=$f+$s;
break;
case '-':
$res=$f-$s;
break;
case '*':
$res=$f*$s;
break;
case '/':
$res=$f/$s;
break;

}
}
?>
<table>
<form method="post">
<tr>
<td>Result</td>
<td><input type="text" value="<?php echo @$res; ?>" readonly="true"/></td>
</tr><tr>
<td>First number</td><td>
<input type="text" name="f"/></td>
</tr>
<td>Second number</td>
<td><input type="text" name="s"/></td>
</tr>
<tr>
<td>Your Choice</td>
<td><select name="ch">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select></td>
</tr>
<tr><td colspan="2" align="center">
<input type="submit" value="Display Result" name="disp"/>
</td>
</tr></form>
</table>

Another Program For Calculator In Php


So, in this application I am using two input HTML TextBoxes for entering operands for calculations, a button for the calculation and a drop down list for selecting an operator, and a button for the calculation. In it is simply a HTML TextBox value, in other words operand value and also an operator value is accepted in this way:

$_REQUEST['name']

In that way you can simply store the TextBox value or drop down list value for calculation in a PHP variable. I handle lost of errors in this script. I am simply checking that the TextBox value is empty or not using:

if($_REQUEST['fvalue']==NULL && $_REQUEST['lvalue']==NULL)

If an error exists then an alert is shown with a message depending on the error.

The following is the calculator code:

<?php
ini_set('display_errors',0);
if( isset( $_REQUEST['calculate'] ))
{
$operator=$_REQUEST['operator'];
if($operator=="+")
{
$add1 = $_REQUEST['fvalue'];
$add2 = $_REQUEST['lvalue'];
$res= $add1+$add2;
}
if($operator=="-")
{
$add1 = $_REQUEST['fvalue'];
$add2 = $_REQUEST['lvalue'];
$res= $add1-$add2;
}
if($operator=="*")
{
$add1 = $_REQUEST['fvalue'];
$add2 = $_REQUEST['lvalue'];
$res =$add1*$add2;
}
if($operator=="/")
{
$add1 = $_REQUEST['fvalue'];
$add2 = $_REQUEST['lvalue'];
$res= $add1/$add2;
}
if($_REQUEST['fvalue']==NULL && $_REQUEST['lvalue']==NULL)
{
echo "<script language=javascript> alert(\"Please Enter values.\");</script>";
}
else if($_REQUEST['fvalue']==NULL)
{
echo "<script language=javascript> alert(\"Please Enter First value.\");</script>";
}
else if($_REQUEST['lvalue']==NULL)
{
echo "<script language=javascript> alert(\"Please Enter second value.\");</script>";
}
}
?>
<form>
<table style="border:groove #00FF99">
            <tr>
                <td style="background-color:aqua; color:red; font-family:'Times New Roman'">Enter First Number</td>
                <td colspan="1">
             
                    <input name="fvalue" type="text" style="color:red"/></td>
            <tr>
                <td style="color:burlywood; font-family:'Times New Roman'">Select Operator</td>
                <td>
                    <select name="operator" style="width: 63px">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select></td>
               </tr>
            <tr>
                <td style="background-color:aqua; color:red; font-family:'Times New Roman'">Enter First Number</td>
                <td class="auto-style5">
                    <input name="lvalue" type="text"  style="color:red"/></td>
             
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" name="calculate" value="Calculate" style="color:wheat;background-color:rosybrown" /></td>
             
            </tr>
            <tr>
                <td style="background-color:aqua;color:red">Output = </td>
                <td style="color:darkblue"><?php echo $res;?></td>
             
            </tr>
       </table>

 </form>

If You Find This Program " Create A Calculator Using PHP" Helpful Please Leave A Comment And Do Share With Your Friends. If You Have Any Query Related To This Program Please Comment Below . Happy Coding.

You May Also Like:-
How To Count Vowel And Consonant In PHP
How To find Palindrome Number In PHP
Fibonacci series In Php

how to find palindrome number in php

A palindromic number or numeral palindrome is a number that remaining parts a similar when its digits are turned around or turned reversed.
we will discuss here all the questions related to palindrome number.
What is palindrome Number
How to find palindrome number.
PROGRAM FOR PALINDROME NUMBER.
simple program in php to check palindrome number

Program To Check Palindrome Number In Php.


<?php
$num=$_GET['n'];
$p=$num;
while((int)$num!=0)
{
$rem=$num%10;
$sum=$sum*10+$rem;
$num=$num/10;
}

if($sum==$p)
{
echo $p.” is palindrome number”;
}
else
{
echo $p.” is not palindrome number”;
}
?>
<form>
enter your number<input type=”text” name=”n”/>
<input type=”submit” value=”Chk Result”/>
</form>

Another Program For Checking palindrome this would help you remove the spaces and cases


<!DOCTYPE html>
<html>
<head>
<title>String Comparison</title>
<meta charset = "utf-8" />
</head>
<body>
<?php
$theString = "A but tuba";       //the string you are checking
$arrayHolder = array();              //creates an array to hold indexed string
$arrayHolder= str_split($theString);  //breaks the string and stores it in a new variable
$reArrangedString = "";        //this string collects your broken string after rearangement
//The loop condition takes the broken  string, put it in the array one at a time and concates it with the rearrangement var.
for ($i = count($arrayHolder); $i >=0; $i--) {
    $reArrangedString .= $arrayHolder[$i];
}
$spaceErase = strtolower(str_replace(" ","",$reArrangedString));  // variable set to remove space and upper case letter
$theStringSpaceErase = strtolower(str_replace(" ", "", $theString)); // does the same as above
echo "<p>After rearranging, your new word is <strong>$spaceErase</strong></p>";
echo "<p>Your real string is now $theStringSpaceErase</p>";
if ($theStringSpaceErase == $spaceErase) {
    echo"<p>You have a palindrome</p>";
}
else {
echo "<p>You do not have a palindrome</p>";
}
?>
</body>
</html>

Find string palindrome or not in PHP using strrev() function

<?php
$in1 = "level";
echo "String: " . $in1 . "<br>";
$reverse = strrev($in1);
if ($in1 == $reverse)
    echo 'Output: This string is a palindrome';
else
    echo 'Output: This is not a palindrome';
?>

 without using strrev() function

<?php
$mystring = "level"; // set the string
echo "String: " . $mystring;
$myArray = array(); // php array
$myArray = str_split($mystring); //split the array
$len = sizeof($myArray); // get the size of array
$newString = "";
for ($i = $len; $i >= 0; $i--) {
    $newString.=$myArray[$i];
}
echo "<br>";
if ($mystring == $newString) {
    echo "Output: " . $mystring . " is a palindrome";
} else {
    echo "Output: " . $mystring . " is not a palindrome";
}
?>

Another Program For Palindrome


<form method="post">
<input type="text" name="txt"  /><br />
<input type="submit" name="sbt" />
</form>
<?php
error_reporting(0);
$string = $_POST['txt'];
$i=0;
$k = 0;
while( isset($string[$k]) ){
 $k++;
}
$strlen = $k;
$word = "";
while ($i <= $strlen){
 if(ord($string[$i]) == 32){
  $word .= "";
 }
 else{
  $word .= $string[$i];
 }
 $i++;
}
$a = strlen($word);

$word2 = "";
$i = 0;
while ($a >= $i)
{
 $word2 .= $word[$a];
 $a--;
}
if ($word == $word2){
 echo "true";
}
else {
 echo "false";
}
?>

 <form method="post">
<input type="text" name="txt"  /><br />
<input type="submit" name="sbt" />
</form>
<?php
error_reporting(0);
$string = $_POST['txt'];
$i=0;
$k = 0;
while( isset($string[$k]) ){
 $k++;
}
$strlen = $k;
$word = "";

while ($i <= $strlen){
 if(ord($string[$i]) == 32){
  $word .= "";
 }
 else{
  $word .= $string[$i];
 }
 $i++;
}
$a = strlen($word);

$word2 = "";
$i = 0;

while ($a >= $i)
{
 $word2 .= $word[$a];
 $a--;
}
if ($word == $word2){
 echo "true";
}
else {
 echo "false";
}
?>

If you Find This Program Helpful Leave A Comment And Do Share With Your Friends.
If You Have Any Query Related To Any Program On Php You Can Comment Below. Happy Coding.
You May Also Like:-

Fibonacci Series In Php

Q. What Is Fibonacci Series?
The Fibonacci series is a set of numbers that starts with a one or a 0, observed via a one, and proceeds based on the rule of thumb that each quantity (known as a Fibonacci range) is equal to the sum of the previous numbers. if the Fibonacci series is denoted f (n), in which n is the primary time period within the sequence, the following equation obtains for n = 0, wherein the first two terms are defined as zero and 1 by convention:
A Fibonacci Series of numbers will look like
0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55
First two Fibonacci numbers are 0 and 1. After that, each number will be the sum of previous two numbers. Here we can see that third Fibonacci number is 1 ( sum of first two numbers 0 + 1 ), and fourth Fibonacci number will be the sum of third and second number ( 1 + 1 = 2 ) , and fifth Fibonacci number will be the sum of fourth and third number ( 2 + 1 = 3 ). The series will go to that infinity.
Now we can learn how to make a Fibonacci series using PHP.
Here is the PHP script for printing first 20 Fibonacci numbers .
<?php 
$count = 0 ;
 $f1 = 0;
 $f2 = 1;
 echo $f1." , ";
 echo $f2." , ";
 while ($count < 20 ) { $f3 = $f2 + $f1 ; echo $f3." , ";
 $f1 = $f2 ; $f2 = $f3 ; $count = $count + 1; } 
?>
Its output will be :
0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , 233 , 377 , 610 , 987 , 1597 , 2584 , 4181 , 6765 , 10946 ,
Another Program For fibonacci Series In PHP
<?php

function printFibonacci($n)
 {
  $first = 0;
  $second = 1;
  echo "Fibonacci Series \n";
  echo $first.' '.$second.' ';
  for($i = 2; $i < $n; $i++){
    $third = $first + $second;
    echo $third.' ';
    $first = $second;
    $second = $third;
    }
}
  
/* Function call to print Fibonacci series upto 6 numbers. */
printFibonacci(6);

?>

Output Of Above Program

Fibonacci Series 0 1 1 2 3 5


In this example, I have created the series using a while loop.Like this, we can make Fibonacci Series using for loops also in PHP
If You Find This Program Helpful leave A Comment And Do Share With Your Friends.If You Have Any Other Query Related To Any Program Of Php You Can Comment Below.Happy Coding.

 You May Also Like : -
 Code For Checking Password In Php