Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

coloring text in a textarea

Status
Not open for further replies.

mThomas

Instructor
May 3, 2001
404
0
0
US
I am using PHP to grab some text from a text field in a database. The text is inserted into a form textarea. Is it possible to color instances of a word within the textarea. I would like the user, when viewing the text in the textarea, to be able to quickly see instance of a word, like "Comment", by highlighting or color coding all instances of the word Comment. I know with styles I can chang eht e color of all the text in a text area, I would like to change or highlight only specific instances of text.

tia...mike
 
I was hoping that there would be some way of using a conditional statement in PHP to do it. You can not do it in CSS.

I was also hoping with the collective brain power of actual programmers, like PHP programmers, that someone may have come accross a way to do it using PHP.

mike
 
CSS can do this!

Just add something like

textarea
{ color:#0000CC; }


to your CSS definitions.


... and now back to PHP :)
 
Yes, CSS can change the entire textarea. I was wanting to use a conditional statement to selectivly color code instances of text, not all the text. What you suggested would affect all the text in the textarea.

That is why I came to PHP, well... that and the entire project is being done in PHP. The MS SQL result set which populates the text area is being called via PHP. All the markup is being manipulated using PHP.

I think the answer is it can not be done :(

mike
 
mThomas:
I don't understand your question. If your script is about to output "Comment", then put <font> or <div> tags around it.

If necessary, the code to output the HTML will be hard-coded. If necessary, the code to output the HTML will use an if-statement, checking for the word "Comment".


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I want to be able to retrieve content, display it in a textarea and where people have used TGML, have the actual TGML tags show up color coded so they are easily recognizable within the textarea. So if someone edited the contents in the textarea such as:

[Comment]The sky is really blue.[/Comment]

When the textarea content is save to the database and then retrieved, back into a textarea, for further editing, the Comment tags show up color coded within the textarea.

mike
 
I used a TGML type of tag as an example. I want to color code specific instances of words within a textarea. For example, in this textarea I'm typing this message in, I could use TGML. I could then preview my post prior to submitting it. If I elect to edit the post, I want the TGML to be color coded so it stand out.

The project involves having reporters writing artilces for print. They have been using Word. The aritcles are then processed in to .xtg files for insetion into Quark. I am using TGML "like tags" to denote when a Quark tag conversion must take place. There will be a simple conversion application written in VB to convert these "TGML like tags" into Quark tags.

Everything works great. It's a beautiful thing, except if a reporter uses lots of the "TGML type of tags" it gets confusing to edit. I was hoping to be able to color code the tags so they are easier to see.

So if you can imagine, a reported starts writing an article and saves it prior to finihsing it. The reporter then retreives the article. The retrived artilce is displayed within a textarea. The reporter has used instances of text (the TGML like tags) to denote when he or she wants bold text etc... I want those tags to be color coded.

This portion of the project is done in PHP. I was hoping that there was a way, in PHP, to manipulate the contents of a textarea in such a manner as to color code, using markup/css or whatever, the "TGML like tags."

mike
 
At what point are you considering manipulating the contents of a textarea? I hope not before submission to another server, as PHP only runs on servers, not on clients.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
The maninulation would be done after the content has been save to the database server and retrieved. It is when the content is re-displayed that I want the manipulated display.

I really appreciate the attention everyone has given this issue!!
 
The maninulation would be done after the content has been save to the database server and retrieved. It is when the content is re-displayed that I want the manipulated display.

So, they type:
blah blah blah [comment]lalal[/comment]
and the result is
blah blah blah [red]lala[/red]

and hit "preveiw" and you want to get another copy of the same form where the tags are translated into the result?

Why not just show the result in a preview using CSS, PHP and JS while they are typing (like in PHPx (a CMS)). I would suggest not showing the result in an editable form, because removing those tags or fixing them would become harder (like editing in a WYSIWYG html editor (where does bold really begin (is the spave before and after part of the bold or not?)). Or generate a preview above the form, and leave the form with exsactly the same content...

[plug=shameless]
[/plug]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top