PHP program to convert a string into lowercase and uppercase in php
Write a PHP program that will convert a string into lowercase and uppercase
In this tutorial, you will be learning how to convert a string into Uppercase and Lowercase in php.
Below is the php script to convert a string into Uppercase and Lowercase in php.
<html>
<head>
<title>PHP Program to convert a string into Uppercase & Lowercase</title>
</head>
<body>
<h2> Write a PHP program that will convert a string into lowercase string and uppercase string </h2>
<form action="" method="POST">
<input type="text" name="str" placeholder="enter the string here"/></br>
<input type="submit"/></br>
</form>
<?php
if($_POST)
{
$str = $_POST['str'];
if(is_numeric($str))
{
echo "enter a string!!";
die();
}
else
{
for($i=0; $i<strlen($str); $i++)
{
if($str[$i]>='a' && $str[$i]<='z')
{
echo strtoupper($str[$i]);
}
else
{
echo strtolower($str[$i]);
}
}
}
}
?>
</body>
</html>
Thanks for reading.