167. PHP Program to Convert Uppercase text into Lowercase text.
How does this program work?
- This program is used to convert uppercase text into lowercase text using PHP.
Here is the code
<html>
<head>
<title>PHP Program To convert all uppercase into lowercase</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="string" value="" placeholder="Enter a string"/> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
</tr>
</table>
</form>
<?php
function lower($str)
{
$var = str_split($str);
// conversion of string into array
$arrlength = count ($var);
//counting lengh of array
$arr = array();
for($i = 0; $i < $arrlength; $i++)
{
$arr[$i] =ord($var[$i]);
}
for($x = 0; $x < $arrlength; $x++)
{
//To convert uppercase into lowercase
if( $arr[$x]>=65 && $arr[$x]<=92)
{
$arr[$x] = $arr[$x]+32;
}
}
for($j = 0; $j < $arrlength; $j++)
{
$var[$j] = chr($arr[$j]);
}
$name = implode ("",$var); //conversion of array into string
echo $name; //printing string
}
if(isset($_POST['submit'])) {
$str = $_POST['string'];
echo "Input string is : " . $str."</br>";
echo "String in Lower case : ";
lower( $str);
return 0;
}
?>
</body>
</html>