STRING HANDLING AND REVERSING

60


 <html>
<head>
    <title>STRING HANDLING AND REVERSING</title>
</head>
<body>
    <center><b><h1>String Handling and Reversing</h1></b></center>
    <form action="prg5.php" method="get">
        Enter your choice: <input type="text" name="choice"/><br><br>
        <input type="submit" value="Submit"/><br>
    </form>

    <?php
    if (isset($_GET["choice"])) {
        $originalString = $_GET["choice"];

        function analyzeString($str) {
            $upper = $lower = $number = $special = 0;

            // Iterate through each character in the string
            for ($i = 0; $i < strlen($str); $i++) {
                if (ctype_upper($str[$i])) {
                    $upper++;
                } elseif (ctype_lower($str[$i])) {
                    $lower++;
                } elseif (ctype_digit($str[$i])) {
                    $number++;
                } else {
                    $special++;
                }
            }

            echo "No. of uppercase letters: $upper<br>";
            echo "No. of lowercase letters: $lower<br>";
            echo "No. of digits: $number<br>";
            echo "No. of special characters: $special<br>";

            // Reverse the string
            $reversedString = strrev($str);
            echo "The reversed string: $reversedString<br>";

            // Palindrome check
            if (strtolower($str) == strtolower($reversedString)) {
                echo "The input string is a palindrome!";
            } else {
                echo "The input string is not a palindrome.";
            }
        }

        // Call the function to analyze the string
        analyzeString($originalString);
    }
    ?>
</body>
</html>