Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Convert symbols to html code
Old 02-10-2008, 01:57 PM Convert symbols to html code
Extreme Talker

Posts: 176
Trades: 0
On my website (skeddles.com, check it out) I allow users to submit comments.

I just don't want people to be able to use html in their comments, so is there way to convert symbols to a code before I add them to the database.

< to &lt;
> to &gt;

If theres an easy way to do it, then I want to do it with all symbols. If they all need to be done separately, then I just want to do those symbols. Thanks.
Skeddles is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-10-2008, 02:49 PM Re: Convert symbols to html code
carloncho's Avatar
Skilled Talker

Posts: 80
Name: Carlos
Trades: 0
for the two examples you write, the better way is to use php´s htmlentities() function. Then you can strip all html tags with php´s strip_tags() function. But If you convert all symbols maybe you code an own function that with str_replace() replace each symbol.
I code a "sumbit comment" some time ago, and to avoid this problem, i code a javascript function that enable only characters, numbers and some symbols.
__________________
-----------------------

Please login or register to view this content. Registration is FREE
carloncho is offline
Reply With Quote
View Public Profile Visit carloncho's homepage!
 
Old 02-10-2008, 05:41 PM Re: Convert symbols to html code
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
Dim s as string = Form("comment")

s = Replace(s, "<", "&lt")
s = Replace(s, ">", "&gt")
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 02-11-2008, 02:11 PM Re: Convert symbols to html code
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Here's one I prepared earlier

Code:
function toCode(strItem)
	strItem = Replace(strItem,"<","&lt;")
	strItem = Replace(strItem,">","&gt;")
	strItem = Replace(strItem,"%","%")
toCode = strItem	
end function
set for ASP code

@carloncho

In case it escaped your attention, this is the ASP forum so PHP solutions are NOT the best thing to be posting.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-13-2008, 07:06 PM Re: Convert symbols to html code
Extreme Talker

Posts: 176
Trades: 0
Thanks guys, works perfectly(I also added BBcode). My site is pretty much finished.

http://skeddles.com/home.asp

Feel free to browse and leave comments.
Skeddles is offline
Reply With Quote
View Public Profile
 
Old 02-13-2008, 11:01 PM Re: Convert symbols to html code
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
You might want to change your code to not publish email addresses...?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 02-14-2008, 12:42 AM Re: Convert symbols to html code
Extreme Talker

Posts: 176
Trades: 0
Quote:
Originally Posted by ForrestCroce View Post
You might want to change your code to not publish email addresses...?
why is that?
You mean so only i can email them? That's probably a good idea.

EDIT: Done

Last edited by Skeddles; 02-14-2008 at 12:52 AM..
Skeddles is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Convert symbols to html code
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.64486 seconds with 12 queries