Answer to Question #186892 in HTML/JavaScript Web Application for Kgabo Makhwiting

Question #186892

Write the PHP script called remove.php and create an HTML form for your web page that removes lines of text from a given file, the file contains sentences, and it is called textfile.txt. Your we page contains a short form with a text box and text field where the customers or users can type only one word. Then the web page should provide the following behaviors: • The web page displays the current contents of the file text.txt as it appears in the file with its format.• The web page form submits back to the same page, remove.php, as a post request. • Display changes of the file to any future viewings of the web page and display how many sentences were removed from the textfile.txt. • Do not used browser's default styling. You are required to write any suitable CSS style. • Ensure that the results are displayed in red color and the number of sentences removed are displayed in green colour.


1
Expert's answer
2021-04-28T23:28:56-0400
<html>
<head>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<style>
div.solid{
border-style: solid;
}
</style>
</head>
<body>

<h3 class="w3-center"><b>Word Removing</b></h3>
<br>
<div class="w3-light-grey w3-center w3-row" style="padding: 40px;">
<form action="" method="post">
<table>
<tr>
<td>
Remove word:</td> <td> <input type="text" name="removeword" class="w3-input" /> </td></tr>
<tr>
<td>
<br/><br/>
<center><input type="submit" name="submit" class="w3-button w3-blue" value="Submit"></center>
</td></tr>
</table>
</form>
</div>
<?php
if(!isset($_POST['submit'])){
?><div class="solid " style="margin-left: 50px;margin-right: 50px;margin-top:20px;"><?php
echo file_get_contents( "interview.txt"); // displays the content before removing lines containing word.
?>
  
</div>
<?php
}
else
if(isset($_POST['submit'])){

$rows = file("interview.txt");
$word=$_POST['removeword'];
$flag=0;
foreach($rows as $key => $row) {
if(preg_match("/($word)/", $row)) {
unset($rows[$key]);
$flag=1;
}
}
if($flag==0)
{
?><div class="solid" style="margin-left: 200px;margin-right: 50px;margin-top:20px;"><?php
echo "No word found"; // displays the error if no word found.
}
?>
  
</div><?php

file_put_contents("interview.txt", implode("\n", $rows));
?>
<div class="solid " style="margin-left: 50px;margin-right: 50px;margin-top:20px;"><?php
echo file_get_contents( "interview.txt" ); // displays the content after removing lines containing word.
}?></div>
</body>
</html>

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS