Just use str_replace
, Don't go against the grain.
http://php.net/manual/en/function.str-replace.php
str_replace — Replace all occurrences of the search string with the replacement string
<?php
parse_str(file_get_contents("php://input"), $_POST);
if (isset($_POST['text'])&&isset($_POST['search'])&&isset($_POST['replace'])) {
$text = $_POST['text'];
$search = $_POST['search'];
$replace = $_POST['replace'];
$text = str_replace($search, $replace, $text);
echo $text;
}
?>
<hr>
<form action="new.php" method="POST" name="form">
<textarea name="text" rows="6" cols="30" ></textarea><br><br>
search <br><br>
<input type="text" name="search" ><br><br>
replace<br><br>
<input type="text" name="replace" ><br><br>
<input type="submit" value="Submit"><br><br>
</form>