PHP –– str_replace
written by: admin
Date Written: 2/21/10
Last Updated: 6/20/11
This is a simple yet handy program for quickly editing a text document. This assumes magic quotes are turned off.
<?php
$string = $_POST['data'];
$word1 = $_POST['word1'];
$word2 = $_POST['word2'];
$string=str_replace("$word1","$word2",$string);
$word1=htmlentities($word1);
$word2=htmlentities($word2);
?><body style='background-color:tan;'>
<form action=<?php echo $_SERVER['PHP_SELF']; ?> method="POST">
Enter text document here:
<br>
<textarea rows=35 cols=130 name="data"><?php print $string; ?></textarea>
<br><textarea cols="45" rows="4" name="word1"><?php print $word1; ?></textarea>< -- Remove this
<br><textarea cols="45" rows="4" name="word2"><?php print $word2; ?></textarea>< -- and replace it with this
<br><input type='submit' name="queryButton" value="Submit">
</form></body>
You can try it out
here.
replace hyphens
The following is a test page where the "
convert hyphens to dashes" PCRE can be tested.
Try it out
here.
TAGS: php