loader image

PHP Program to reverse a string

Write a PHP program to reverse a string without strrev function.

<html>

<body>
    <form action="" method="POST">
        <H1>Reverse a string</h1>
        Enter the string :
        <input type="text" name="str" />
        <input type="submit" />
    </form>

</html>
<?php
if ($_POST) {
    $string = $_POST["str"];
    $len = strlen($string);
    for ($i = ($len - 1); $i >= 0; $i--) {
        echo $string[$i];
    }
}
?>
Output
reverse php
Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
adil

there is a mistake in between heading “biodata”
<form action=“” method=“POST”>

<H1>Biodata</h1>

Enter the string :

Scroll to Top