I have a text box, a search field, and a replace field. I want to perform a search and replace for the text in my text box and change the color of the font for any of the replaced words. I would like any words that are not replaced to remain the font color they were before the search/replace was performed.
Scratching my head on this one though. Here's the code I've got so far:
<body>
<form id="form1" name="form1" method="post" action="">
<p><br/>
<textarea name="textarea" id="textarea" cols="70" rows="10">
<?php
if(isset($_POST["submit"])) {
$search = $_POST["search"];
$replace = $_POST["replace"];
$textarea = $_POST["textarea"];
$newtext = str_replace($search,$replace,$textarea);
echo $newtext;
}
?>
</textarea>
</p>
<p>
<label for="search">Search :</label>
<input type="text" name="search" id="search" />
</p>
<p>
<label for="replace">Replace</label>
<input type="text" name="replace" id="replace" />
</p>
<p><br/>
<input type="submit" name="submit" id="submit" value="Submit" />
<label for="textarea"></label>
</p>
</form>
</body>
</div>