PHP program to demonstrate string functions

PROGRAM
<?php
echo "
<form method='POST' action='' >
FIRST :<input type='text' name='first'>
SECCOND :<input type='text' name='seccond'>

<input type='submit' value='submit' name='submit'>
</form>
";
if(isset($_POST['submit']))
{
$first=$_POST['first'];
$seccond=$_POST['seccond'];
echo "STRING ONE: " . $first."</br>";
echo "STRING TWO: " . $seccond."</br>";
echo "</br>";


echo "<u><h2>string position(strpos())</h2></u></br>";
$pos=strpos($first,$seccond);
if($pos==false)
{
echo  "the string " .  $seccond . " not found";
}
else
{
echo "the string " . $seccond . " find " . " at " . $pos . " position" ;
}
echo "<br/><br/>";
echo "<U>"."STRING LENG FUNCTION (strlen())"."</U>"."<br/>";
echo "string length of ".$first." ".strlen($first);
echo "</br>";
echo "string length of ".$seccond." ".strlen($seccond);

echo "<br/>";echo "<br/>";
echo "<br/>";

echo "<U>"."STRING COMPARISON(strcmp)"."</U>"."<br />";
$value=strcmp($first,$seccond);
if($value<0)
{
echo $first." is "." LESTHAN ".$seccond;
}
else if($value>0)
{
echo $first." is "." GREATERTHAN ".$seccond;
}
else if($value==0)
{
echo "two are equal";
}

echo "<br/>";
echo "<br/>"."<U>"."STRING UPPER CASE AND LOWERCASE(strtolower and strtoupper)"."</U>"."<BR/>";
echo "FIRST STRING IS LOWRCASED " . " ". strtolower($first);echo "<br/>";
echo "SECCOND STRING IS UPPERCASED " . strtoupper($first);echo "<br/>";
echo "Two string are upper cased the first letters. " . ucfirst($first) . " and " . ucfirst($seccond);
}

?>

OUTPUT



No comments:

Post a Comment