getting rid of special characters?
MarkGauthier | Posted 8:51pm 27. September 2007 Server Time |
I have a guestbook based on the ASP guestbook lesson on this website!
I would like to omit any special characters that aren't allowed in file names (eg \ / : * . ! ? < > | ) from the resulting written file.
http://www.marky-mark.com/clog.asp
this is the initial page you arrive at to submit your "community blog"
http://www.marky-mark.com/clogwrite.asp
this is my write file that outputs two text files
http://www.marky-mark.com/clogthanks.asp
this is the thank you for submitting page |
MarkGauthier | Posted 8:52pm 27. September 2007 Server Time |
P.S. im sorry for posting this twice :(
katy8439 | Posted 1:50am 28. September 2007 Server Time |
You can use regular expressions to remove any characters you don't want
<%
MyFileName="something\this*Not!Allowed.jpg"
Dim objRegExp, strOutput
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
'** List the characters that are invalid
objRegExp.Pattern = "[\\\/:\*\!?""<>|]"
'Replace all invalid tag matches
CleanFileName = objRegExp.Replace(MyFileName, "")
Response.Write CleanFileName
Set objRegExp = Nothing
%>
MarkGauthier | Posted 2:56pm 28. September 2007 Server Time |
sorry I'm sort of a newbie at this.
where abouts would I put that?
katy8439 | Posted 8:49am 1. October 2007 Server Time |
Looking at the pages that you mentioned, you'd add it in the clogwrite.asp page.
If you haven't changed the original Guestbook code too much then the file, with my code included, would look like:
<%
'*****************************************************
'* Code written by Alexander Haneng (C) 1998-2001 *
'* FREE download from http://www.haneng.com/ *
'*****************************************************
'Type in the path of the file to use. Make sure that the script has write access.
MyFile = "c:\guestbook.txt"
Dim objRegExp, strOutput
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
'** List the characters that are invalid
objRegExp.Pattern = "[\\\/:\*\!?""<>|]"
'Replace all invalid tag matches
MyFile = objRegExp.Replace(MyFile, "")
Response.Write CleanFileName
Set objRegExp = Nothing
'Ready Scripting.FileSystemObject
Set MyFileObj=Server.CreateObject("Scripting.FileSystemObject")
'Opens textfile. 8 = add line to file, true = create if it doesn't exists
Set MyOutStream=MyFileObj.OpenTextFile(MyFile, 8, TRUE)
'Writes the line to the file
New_line = Request.Form("new_line")
New_line = Server.HTMLEncode(New_line)
'Adds the time and date it was posted
New_line = "<I>Posted: " & NOW & "</I><BR>" & New_line
MyOutStream.WriteLine(New_line)
'Closes the file
MyOutStream.Close
'Sends them back to the default page
Response.Redirect "clogthanks.asp"
%>
katy8439 | Posted 8:51am 1. October 2007 Server Time |
Sorry, ignore the above - I put the clean up code in the wrong place. Should be:
<%
'*****************************************************
'* Code written by Alexander Haneng (C) 1998-2001 *
'* FREE download from http://www.haneng.com/ *
'*****************************************************
'Type in the path of the file to use. Make sure that the script has write access.
MyFile = "c:\guestbook.txt"
'Ready Scripting.FileSystemObject
Set MyFileObj=Server.CreateObject("Scripting.FileSystemObject")
'Opens textfile. 8 = add line to file, true = create if it doesn't exists
Set MyOutStream=MyFileObj.OpenTextFile(MyFile, 8, TRUE)
'Writes the line to the file
New_line = Request.Form("new_line")
'** Clean Up The New Line and get rid of any invalid characters
Dim objRegExp, strOutput
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
'** List the characters that are invalid
objRegExp.Pattern = "[\\\/:\*\!?""<>|]"
'Replace all invalid tag matches
New_line = objRegExp.Replace(New_line, "")
Set objRegExp = Nothing
New_line = Server.HTMLEncode(New_line)
'Adds the time and date it was posted
New_line = "<I>Posted: " & NOW & "</I><BR>" & New_line
MyOutStream.WriteLine(New_line)
'Closes the file
MyOutStream.Close
'Sends them back to the default page
Response.Redirect "clogthanks.asp"
%>
Reply to Post getting rid of special characters?
|
|
|