Untitled

 avatar
unknown
plain_text
a month ago
1.2 kB
4
Indexable
<!DOCTYPE html>

<html>

<head>

<title>String Functions</title>

</head>

<body>

<h2>PHP Program to Demonstrate String Functions</h2>

<form method="post">

Enter String 1: <input type="text" name="s1" required value="<?php echo

isset($_POST['1']) ? $_POST['1']: "; ?>"><br><br>

Enter String 2: <input type="text" name="s2" required value="<?php echo

isset($_POST['2']) ? $_POST['s2']: "; ?>"><br><br>

<input type="submit" name="submit" value="Submit">

</form>

<br>

<?php

if (isset($_POST['submit'])) {

    $n1=$_POST['s1'];

    $n2 = $_POST['s2'];

    echo "Results":

    echo "String 1 before: ".$n1. "<br>";

    echo "String 2 before: ".$n2. "<br>";

    echo "The length of String 1 is: ".strlen($n1). "<br>";

    echo "The reverse of String 2 is: ".strrev($n2). "<br>";

    echo "The replaced String 1 is: ".str_replace($n1, "JGI", $n1). "<br>";

    echo "The number of words in String 2 are: ".str_word_count($n2). "<br>";

    echo "String 1 in uppercase:" strtoupper($n1)."<br>";

    echo "String 2 in lowercase: ". strtolower($n2). "<br>";
}
if (strcmp($n1, $n2) == 0) {

    echo "The strings are equal.<br>";

} else {

    echo "The strings are NOT equal.<br>";

}



?>

</body>

</html>

}
Editor is loading...
Leave a Comment