Write a PHP script that receive string as a form input

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["text"])) {
    $text = htmlspecialchars($_POST["text"]);
    echo "You entered: $text";
}
?>

<!DOCTYPE html>
<html>
<body>
    <form method="post">
    Enter a text: <input type="text" name="text" required>
        <input type="submit" value="Submit">
    </form>
</body>
</html>