Click to See Complete Forum and Search --> : tag replacement


anarchist
07-02-2003, 05:12 AM
I have a problem where our clever server stuff hanels thigs how it wants to, which isnt always how we want it to, we cant change the behaviour of the server so are relying on workarrounds to get the functionality we need

the current problem is when you enter text into a RTF text area our clever server returns the < as &lt; and > as &gt; this is no longer what we want so, I'm asking how do I convert the &gt;s and &lt;s back into > and < ?

David Harrison
07-02-2003, 05:31 AM
I'll give you a javascript script as that's all I know (as opposed to server side).

while(string.indexOf("&gt;")>=0){string.replace("&gt;",">");}
while(string.indexOf("&lt;")>=0){string.replace("&lt;","<");}

Charles
07-02-2003, 05:35 AM
We can shorten that up a bit by using the "g" flag with the regular expressions and by stringing the objects together.

<script type="text/javascript">
<!--
s = '&lt;&lt;&gt;&gt;'
alert(s.replace(/&lt;/g, '<').replace(/&gt;/g, '>'))
// -->
</script>

David Harrison
07-02-2003, 05:42 AM
I'll have to go home and read about those, reg exp's tonight.

anarchist
07-02-2003, 05:45 AM
thanks that should sort things perfectly

anarchist
07-03-2003, 09:38 AM
I now have a new problem based on my earlier problem, my earlier problem was converting messed up rich text to working code, or HTML, my new problem is how text is handeled, my server doesnt know the difference between plain text and rich text and just assumes plain text
we have 2 screens a display one and an edit one

on the display screen if a new line is encountered a <br> tag is added, this is fine for old entries from before I added rich text(HTML) editing, but meens extra <br> tags are added when rich text is used - quite possably in the middle of other tage

and on the edit screen, text is loaded into the editor only wthout extra <br> tags , which is fine for rich text but not for plain

if you havnt already guessed what I need to know is, can anyone suggest a way of deciding if text is rich text or plain text based just on the content

I've just been looking and it appears that the <br>s are added after a new line for plain text, and if they are in rich text then they tend not to have new lines

I think I've come up with a solution, thanks to our server being clever the plain text on the display screen contains <br> tags but rich text on the same screen contains &gt; and &lt; aswell as <br> tags, so if I check to see if the string contains the &gt; and &lt; then its rich text, otherwise its plain text so leave it alone

on on the editor screens if I check for < and > then its rich text so leave it alone otherwise its plain text and needs <br>s adding

ok I think I've solved the problem, unless some one has a better idea (apart from get some better server code)

can someone tell me waht function I need to detect if a strings within a string?
I think its something like instr in VB or maybe it was C, but I'm unsure how it would be used in javascript even if its the right function

anarchist
07-03-2003, 10:12 AM
sorry about that, I actaully posted it here first then thought it should have been a new thread, so made the new one and deleted the original post
sorry again

anarchist
07-03-2003, 11:13 AM
managed it for the editing screens and my code on the display screens seems to work

it was s.indexOf() I needed so I wasnt far off with the instr

shame no one can help me add the code I need to every page that needs it, oh and add a spell checker to each editor too(I'm not asking for help with that yet thoough)