I have written this code to take the sting from the textbox and want to replace any badwords with "***" but I don't know why I am getting one extra "1" at the end..you can have a look of output in the picture.
here is my code
<!DOCTYPE>
<html>
<head>
<title> Mind Your Language </title>
</head>
<body>
<form action="" method="post">
<input type="text" name="string">
<input type="submit" name="submit" value="Filter">
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])) {
$badWords = ['badword1', 'badword2', 'badword3', 'badword4', 'badword5'];
$string = $_POST['string'];
foreach($badWords as $badWord) {
$string1 = str_replace($badWord, "***", $string);
}
echo print_r($string1);
}
?>