0% found this document useful (0 votes)
5 views6 pages

PHP A7

The document outlines a PHP program that creates a user form for string manipulation, allowing users to perform various operations such as getting the length, reversing, changing case, replacing characters, checking for palindromes, shuffling, and counting words. Each operation is triggered by a corresponding submit button, and the results are displayed on the webpage. Specifically, the program includes functionality to replace the letter 'a' with 'x' in the input string.

Uploaded by

agastua8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

PHP A7

The document outlines a PHP program that creates a user form for string manipulation, allowing users to perform various operations such as getting the length, reversing, changing case, replacing characters, checking for palindromes, shuffling, and counting words. Each operation is triggered by a corresponding submit button, and the results are displayed on the webpage. Specifically, the program includes functionality to replace the letter 'a' with 'x' in the input string.

Uploaded by

agastua8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

PART-A III BCA

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">

<label for="string">Enter a string:</label><br>

<input type="text" id="string" name="string"><br><br>

<input type="submit" name="get_length" value="Get Length">

<input type="submit" name="reverse" value="Reverse">

<input type="submit" name="uppercase" value="Uppercase">

<input type="submit" name="lowercase" value="Lowercase">

<input type="submit" name="replace" value="Replace">

<input type="submit" name="check_palindrome" value="Check Palindrome">

<input type="submit" name="shuffle" value="Shuffle">

<input type="submit" name="word_count" value="Word Count">

</form>

<?php

PHP and MySQL Lab Page 23


PART-A III BCA

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

$string=$_POST['string'];

echo"<p>Length of the string:".strlen($string)."</p>";

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);

echo"<p>String after replacement:".$new_string."</p>";

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

$string=$_POST['string'];
PHP and MySQL Lab Page 24
PART-A III BCA

if($string==strrev($string)){

echo"<p>The string is a palindrome.</p>";

}else{

echo"<p>The string is not a palindrome.</p>";

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>

PHP and MySQL Lab Page 25


PART-A III BCA

OUTPUT:

PHP and MySQL Lab Page 26


PART-A III BCA

PHP and MySQL Lab Page 27


PART-A III BCA

PHP and MySQL Lab Page 28

You might also like