Click to See Complete Forum and Search --> : str_replace in <textarea>
Daot Lagorille
11-10-2004, 11:18 AM
Here's a puzzler:
I have a bunch of text in an array, within a textarea:
<textarea><?php echo $row_Stuff['blurb']; ?></textarea>
that I want to do a str_replace on in order to make certain keywords appear red.
How? Regular HTML obviously doesn't work in the <textarea> tag...or does it? Is there a way to escape the tags or something?
dreamcatcher
11-10-2004, 11:31 AM
You could try something like this:
$keywords = array("one", "two", "three");
echo "<textarea>" . str_replace($keywords, '<font color=\"red\">$keywords</font>', $row_Stuff['blurb']) . "</texarea>\n";
Havent tested it, but should work. :)
Oops, just realised what a silly reply that was. Font tags in a text area. hee hee! Maybe you can modify it using CSS? Sorry.
Daot Lagorille
11-10-2004, 11:42 AM
Heh. My problem exactly. I am not sure how CSS would help, as I need a specific word within the textarea, not the whole textarea tag...
Ben Rogers
11-10-2004, 03:38 PM
May I ask why you're using a <textarea>? Is it meant to be modified by the user at all, or do you just want the white space preseved? If so, just use <pre>, and you can use <em>blah</em> with pre em {color: red;} in your source.
Daot Lagorille
11-10-2004, 03:44 PM
Originally posted by Ben R.
May I ask why you're using a <textarea>? Is it meant to be modified by the user at all...
Yessir. Essentially, it is a textfield that contains the default content of an e-mail to be sent. The things to highlight in red are stuff like "Date X, location Y" to make sure that the user remembers to fill them in with meaningful data (data which unfortunately is esoteric enough to not be able to be generated by the database...).
Ben Rogers
11-10-2004, 03:57 PM
Ah. Would it be possible to have this sort of information instead put in through an <input>, so it'd be easier to check if they did in fact input it? (No, you can't make a certain value within a <textarea> look different than the rest of it.)
Daot Lagorille
11-11-2004, 09:46 AM
Yeah...I thought of that too. Kind of a pain in the ass though, especially because it is there just to make sure that users don't screw up.
One other idea I have tried is to do a str_replace on the text that goes in the textarea, and make the replacement string this:
"\r\n\r\n****HEY REPLACE THIS NOW YOU FOOL****\r\n\r\n"
but it wasn't well recieved by the users for some reason.
Ben Rogers
11-11-2004, 11:32 AM
Originally posted by Daot Lagorille
Yeah...I thought of that too. Kind of a pain in the ass though, especially because it is there just to make sure that users don't screw up.
One other idea I have tried is to do a str_replace on the text that goes in the textarea, and make the replacement string this:
"\r\n\r\n****HEY REPLACE THIS NOW YOU FOOL****\r\n\r\n"
but it wasn't well recieved by the users for some reason. LOL. Well, it must've gotten their attention, though, eh? I guess you'll just have to do something like that and just not ridicule the user (the crybaby :p) so much. ;)