PHP A7
PHP A7
7. Write a PHP program that includes a user form with a text field and submit
buttons for various string manipulations. It will display the result accordingly.
(for replace, replace ‘a’ with ‘x’).
<!DOCTYPE html>
<html>
<head>
<title>String Manipulation</title>
</head>
<body>
<h2>String Manipulation</h2>
<form method="post">
</form>
<?php
if(isset($_POST['get_length'])){
$string=$_POST['string'];
if(isset($_POST['reverse'])){
$string=$_POST['string'];
echo"<p>Reversed string:".strrev($string)."</p>";
if(isset($_POST['uppercase'])){
$string=$_POST['string'];
echo"<p>Uppercase string:".strtoupper($string)."</p>";
if(isset($_POST['lowercase'])){
$string=$_POST['string'];
echo"<p>Lowercase string:".strtolower($string)."</p>";
if(isset($_POST['replace'])){
$string=$_POST['string'];
$new_string=str_replace('a','x',$string);
if(isset($_POST['check_palindrome'])){
$string=$_POST['string'];
PHP and MySQL Lab Page 24
PART-A III BCA
if($string==strrev($string)){
}else{
if(isset($_POST['shuffle'])){
$string=$_POST['string'];
echo"<p>Shuffled string:".str_shuffle($string)."</p>";
if(isset($_POST['word_count'])){
$string=$_POST['string'];
echo"<p>Word count:".str_word_count($string)."</p>";
?>
</body>
</html>
OUTPUT: