/    Sign up×
Community /Pin to ProfileBookmark

str_replace in <textarea>

Here’s a puzzler:

I have a bunch of text in an array, within a textarea:

[code=php]<textarea><?php echo $row_Stuff[‘blurb’]; ?></textarea>[/code]

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?

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@dreamcatcherNov 10.2004 — You could try something like this:

[code=php]
$keywords = array("one", "two", "three");

echo "<textarea>" . str_replace($keywords, '<font color="red">$keywords</font>', $row_Stuff['blurb']) . "</texarea>n";[/code]


Havent tested it, but should work. ?

[b]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. [/b]
Copy linkTweet thisAlerts:
@Daot_LagorilleauthorNov 10.2004 — 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...
Copy linkTweet thisAlerts:
@Ben_RogersNov 10.2004 — 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 [i]pre em {color: red;}[/i] in your source.
Copy linkTweet thisAlerts:
@Daot_LagorilleauthorNov 10.2004 — [i]Originally posted by Ben R. [/i]

[B]May I ask why you're using a <textarea>? Is it meant to be modified by the user at all...[/B][/QUOTE]


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...).
Copy linkTweet thisAlerts:
@Ben_RogersNov 10.2004 — 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.)
Copy linkTweet thisAlerts:
@Daot_LagorilleauthorNov 11.2004 — 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:

"rnrn****HEY REPLACE THIS NOW YOU FOOL****rnrn"

but it wasn't well recieved by the users for some reason.
Copy linkTweet thisAlerts:
@Ben_RogersNov 11.2004 — [i]Originally posted by Daot Lagorille [/i]

[B]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:



"rnrn****HEY REPLACE THIS NOW YOU FOOL****rnrn"



but it wasn't well recieved by the users for some reason. [/B]
[/QUOTE]
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. ?
×

Success!

Help @Daot_Lagorille spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...