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

Posts: 77
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
 
When You Register, These Ads Go Away!
     
Old 02-10-2008, 01:49 PM Re: Convert symbols to html code
carloncho's Avatar
Skilled Talker

Posts: 80
Name: Carlos
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.
__________________
-----------------------
http://www.xumby.com
carloncho is offline
Reply With Quote
View Public Profile Visit carloncho's homepage!
 
Old 02-10-2008, 04:41 PM Re: Convert symbols to html code
ForrestCroce's Avatar
Half Man, Half Amazing

Latest Blog Post:
Talapus Lake in June Snow
Posts: 3,016
Name: Forrest Croce
Location: Seattle, WA
Dim s as string = Form("comment")

s = Replace(s, "<", "&lt")
s = Replace(s, ">", "&gt")
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 02-11-2008, 01:11 PM Re: Convert symbols to html code
chrishirst's Avatar
Super Moderator

Posts: 11,452
Location: Blackpool. UK
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!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-13-2008, 06:06 PM Re: Convert symbols to html code
Skilled Talker

Posts: 77
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, 10:01 PM Re: Convert symbols to html code
ForrestCroce's Avatar
Half Man, Half Amazing

Latest Blog Post:
Talapus Lake in June Snow
Posts: 3,016
Name: Forrest Croce
Location: Seattle, WA
You might want to change your code to not publish email addresses...?
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 02-13-2008, 11:42 PM Re: Convert symbols to html code
Skilled Talker

Posts: 77
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-13-2008 at 11:52 PM.
Skeddles is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Convert symbols to html code
 

Thread Tools

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

vB 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.13947 seconds with 13 queries