Sunday, January 1, 2012

Ajax Example in PHP

Example



<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
var XMLHttpRequestObject = false;
if(window.XMLHttpRequestObject)
{
   XMLHttpRequestObject = new XMLHttpRequest(); 
}
else if(window.ActiveXObject)
{
  XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}
function getdata(datasource, divid)
{
  if(XMLHttpRequestObject)
  { 
    var obj = document.getElementById(divid);
XMLHttpRequestObject.Open("GET",datasource+document.getElementById("tb1").value);
XMLHttpRequestObject.onreadystatechange = function()
{
 if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
 {
   obj.innerHTML = XMLHttpRequestObject.responseText;
    


 }
}
XMLHttpRequestObject.send(null);
}
}    




</script>


</head>


<body>
<form>
<input name="tb1" type="text">
<input name="submit" type="button" value="cllick me" onClick="getdata('http://localhost/ajax/ajax2.php?tb1=','targetdiv')">
</form>
<div id = "targetDiv">
<p>fetched msg</p>
</div>
</body>
</html>

Random Function in PHP

Example



<body bgcolor="#CCCCFF">
<font size="+4" ><center>RANDOM FUNCTION DEMO</font></marquee></center><br><br><br>
</head>
<body>
<?php

echo "Generate Random Number Between (50 to 200) [using rand()] ::".rand(50,200);
echo "<br><br>";
//echo "Generated Number [using srand()] ::".srand(20);
//echo "Generated Number [using mt_srand()] ::".mt_srand(20);

echo "Generate Maximum No Of Integer [using getrandmax()]::".getrandmax();
echo "<br><br>";
echo "Generate Number Betwee (0 & 100) [using mt_rand()] ::".mt_rand(0,100);
echo "<br><br>";
echo "Generate Largest Possible Value [using getrandmax()] ::".mt_getrandmax();
echo "<br>";
?>
</body>

Odd/Even/Prime Example in PHP

Example



<body>
<form id="form1" name="form1" method="post" action="">
  <label>ENTER NUMBER::
  <input type="text" name="t1" />
  </label>
  <p>&nbsp;</p>
  <p>
    <label>
    <input type="submit" name="b1" value="Submit" />
    </label>
  </p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>


<?php


if(isset($_POST["b1"]))
{
if(is_numeric($_POST["t1"]))
   {
 if($_POST["t1"]%2==0)
 {
echo $_POST["t1"]." IS EVEN";
 }
 else
 {
echo $_POST["t1"]." IS ODD";
 }
 $i=2;
 
while($i<$_POST["t1"])
       {
if($_POST["t1"]%$i==0)
{
  echo "\n"." & It is not Prime Number";
  break;
}
$i++;
       }
       if($i==$_POST["t1"])
       {
echo "\n"." &  it is Prime Number";
       }
}
 
  else
  {
  echo "INPUT A NUMBER !!";
  }
}

?>
</form>
</body>

Date/Time Function in PHP

Example



<body bgcolor="#CCCCFF">
<font size="+4" ><center>DATE/TIME FUNCTION DEMO</font></marquee></center><br><br><br>
</head>
<?Php


//echo "CHECK IN DATE(DD/MM/YY FORMAT) WHETHER EXIST OR NOT::".checkdate(12,24,2010);
////echo "<br>";
//echo time();
echo "<br>";
//echo date("ddmmyy");
echo "<br>";
//echo localtime();
//echo time();
echo "<br>";
//echo gettimeofday();
//echo idate();
echo "<br>";






echo "(dd mon, year | time) :";
echo date("j M, Y");
echo " | ";
echo date("g:i a");
echo " | ";
echo date("H:i:s");
?>




String Function In PHP

Example



<body bgcolor="#CC99CC">
<font color="#993300" size="+2"><center>STRING FUNCTION DEMO</font><br><br>
</head>

<body>

<form id="form1" name="form1" method="get" action="">
  <label>EnterString::
  <textarea name="textarea"></textarea>
  </label>
  <label>ENTER SECOND STRING
  <input type="text" name="tf" />
  </label>
<label></label>
  <p>&nbsp;</p>
  <p>
    <label>
    <input type="submit" name="b1" value="Submit" />
    </label>
  </p>
</form>

<?php

if(isset($_GET["b1"]))
{

$tf=$_GET["tf"];
$s=$_GET["textarea"];

echo "1.LENGTH OF STRING IS::"." ".strlen($s)."<p>";
echo "2.REVERSE OF STRING IS::"." ".strrev($s)."<p>";
echo "3.UPPER CASE OF STRING::"." ".strtoupper($s)."<p>";
echo "4.LOWER CASE OF STRING::"." ".strtolower($s)."<p>";
echo "5.RETURN 0 IF BOTH STRING ARE SAME::"." ".strcmp($s,$tf)."<p>";
echo "6.REPEATATION OF STRING ::"." ".str_repeat($s,2)."<p>";
echo "7.CASE COMPARE::"." ".strcasecmp($s,$tf)."<p>";
echo "8.SUBSTRING::"." ".substr($s,1,4)."<p>";
$b=array('you','are',$tf,$s);
echo "9. USING JOIN::".join(" ",$b)."<p>";
echo "10. STRING REPLACE::".str_replace("sur",$tf,$s)."<p>";
}
?>
</body>

Array Demo in PHP

Example



<body bgcolor="#CCCCFF">
<font size="+4" ><center>ARRAY DEMO</font></marquee></center><br><br>
</head>
<body>
<?php


$test=array(501=>"ITIM",502=>"UNIX",503=>"AWT",504=>"JAVA",505=>"PHP",506=>"PRACTICAL");
echo "<h4>"."1.NUMBER OF ITEMS STORED IN ARAAY ARE::".count($test)."(using count())"."<br><br>";
echo "2.SCROLLING THE ITEMS:"."<br><br>";
echo "Current::".current($test)."<br>";
echo "Next::".next($test)."<br>";
echo "Prev::".prev($test)."<br>";
echo "Last::".end($test)."<br><br>";
echo "3.STORED ITEM IN ARRAY ARE AS FOLLOWS(using foreach loop)"."<br><br>";
foreach($test as $a)
{
echo $a;
echo "<br>";
}
echo "<br><br>";
/*do
{
echo current($test);
echo "<br>"
}while($a=next($test))*/


echo "4. ARRAY INSPECTION (ISARRAY)::".is_array($test)."<br>";




?>
</body>