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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Striping < ' > & from Strings and replacing them with Html Equivalents 1

Status
Not open for further replies.

Johno2090

Programmer
May 3, 2002
31
GB
I am looking for some asp code that will strip some user inputed code and remove ' < > & characters which have been crashing my applications. I have searche allover the web but have been unable to find anything of use.
 
You can use the Replace function like this
Replace(Source,Find,Replacement)
example
Replace(&quot;blah&quot;,&quot;h&quot;,&quot;H&quot;) ' this returns blaH
to replace with a blank no space
Replace(&quot;bla>h&quot;,&quot;>&quot;,&quot;&quot;) ' returns blah I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
I suggest killing all html then only allowing the html you want such as bold etc..

Do this by doing this...

Code:
<%

Function KillHtml(mytext)

Replace(mytext, &quot;<&quot;, &quot;[&quot;)
Replace(mytext, &quot;>&quot;, &quot;]&quot;)

'# Allow these...
Replace(mytext, &quot;[b]&quot;, &quot;<b>&quot;)
Replace(mytext, &quot;[/b]&quot;, &quot;</b>&quot;)

End Function


'# Now to use it go like this...

SomeText = &quot;Hello there! < b>Welcome< /b> and ofcourse my example will be < blink>messed</blink> up...&quot;

Response.Write(KillHtml(SomeText))


%>
 
Any suggestions on removing or replacing the single apostrophe (') used in possessives like &quot;Mary's Info&quot;?

Users will want to use the apostrophe but we know that it doesn't display well.
 
for the single quote, try using:

Replace(mytext, &quot;'s&quot;, &quot;&#146;s&quot;)
 
jkl,

Thanks for the hint. I think that'll do the trick. By the way, do you know the CHR () code for the substitute. I think I will use that to make sure I don't mess it up.
 
looking at my post, i realize it doesn't help much, since the browser interpretted the ascii code into the apostrophe.

Replace(myText,&quot;'&quot;,&quot;&#.146;&quot;)

remove the . in &#.146;

also can use chr(146)
 
Great!

You proved my point and provided an answer all at the same time!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top