-1

I created a form that the user can type first and last name. The result should be replace letter "s" with "5".

The form page code:

<form action="form.php" method="post">
First Name: <input type="text" name="firstname"><br>
Last Name: <input type="text" name="lastname"><br>
<input type="submit">
</form>

The result page code:

<?php 
    echo $_POST= str_replace("s","5",$_POST); 
?>
slavoo
  • 5,798
  • 64
  • 37
  • 39

1 Answers1

0

You're almost there, try the following:

<?php
     $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
     $fullname = $_POST['firstname'] . ' ' . $_POST['lastname'];
     echo str_replace("s", "5", $fullname);
?>

Note that we have sanitized your $_POST array in case the user has input malicious values which could cause XSS attacks. See this answer for more details: https://stackoverflow.com/a/4861211/823549

1000Nettles
  • 2,314
  • 3
  • 22
  • 31