PHP: Replace


The code used for index.php is below:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../styles.css">
    <title>PHP: Replace</title>
</head>
<body>

<h1 class="lesson-h1">PHP: Replace</h1>

<?php
    if(isset($_POST['user-text'])){

        $user_text = htmlentities($_POST['user-text']);
        $user_replace = htmlentities($_POST['user-replace']);
        $user_replacement = htmlentities($_POST['user-replacement']);

        $replaced = str_replace($user_replace, $user_replacement, $user_text);
        $replaced_content = "<h4 style='margin: 0;'>".$user_text ."</h4>Converted To:<h4 style='margin: 0;'>". $replaced ."</h4>";
    }
?>

<form action="index.php" method="post">
    <textarea name="user-text" id="user-text" cols="50" rows="12" placeholder="Insert Text Here" maxlength="1000" required><?php echo $replaced; ?></textarea>
    <input type="text" name="user-replace" id="user-replace" placeholder="Character/s to Replace" maxlength="50" required>
    <input type="text" name="user-replacement" id="user-replacement" placeholder="Replace With" maxlength="50" required>
    <input type="submit" value="Replace">
</form>

<p><?php echo $replaced_content; ?></p>

<?php
    include('../show_code.php');
    show_code('index.php');
?>
    
</body>
</html>