Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Function snippets for character conversion?
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Astralis
Senior Member

USA
1218 Posts

Posted - 12 December 2004 :  17:59:31  Show Profile  Send Astralis a Yahoo! Message
I don't know why some characters are being written in the database as invalid characters, such as the printer's apostrophe, em-dashes, quotes, etc... because sometimes they work.

So, how do I implement a function to correct these characters, or rewrite them as ascii BEFORE they are written into the database? And, do you have a Function I could use?

Edited by - Astralis on 12 December 2004 18:04:40

dayve
Forum Moderator

USA
5820 Posts

Posted - 12 December 2004 :  18:43:54  Show Profile  Visit dayve's Homepage
I thought I answered this for you? The Replace function can be used to create the filters you need. Just apply the function to the values going into the database in your INSERT and UPDATE sql statements.

Go to Top of Page

Astralis
Senior Member

USA
1218 Posts

Posted - 12 December 2004 :  18:49:29  Show Profile  Send Astralis a Yahoo! Message
Yeah, that's what I was looking at. Should there be more characters added to it?

How do I apply it? It may seem obvious, but I'm dealing with some ridiculous Dreamweaver code.

Would you take a look at this mess and tell me how to do it?


<%


editAction = CStr(Request("URL"))

If (Request.QueryString <> "") Then
  editAction = editAction & "?" & Request.QueryString
End If

abortEdit = false

editQuery = ""


If (CStr(Request("insert")) <> "") Then

  editConnection = articleConn_STRING
  editTable = "articles"
  editRedirectUrl = "admin_list_inactive.asp"
  fieldsStr  = "REMOVED FOR LENGTH"
  columnsStr = "REMOVED FOR LENGTH"

  fields = Split(fieldsStr, "|")
  columns = Split(columnsStr, "|")
  
  For i = LBound(fields) To UBound(fields) Step 2
  fields(i+1) = CStr(Request.Form(fields(i)))
  Next

  If (editRedirectUrl <> "" And Request.QueryString <> "") Then
  If (InStr(1, editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
  editRedirectUrl = editRedirectUrl & "?" & Request.QueryString
  Else
  editRedirectUrl = editRedirectUrl & "&" & Request.QueryString
  End If
  End If

End If
%>
<%

If (CStr(Request("insert")) <> "") Then

  tableValues = ""
  dbValues = ""
  For i = LBound(fields) To UBound(fields) Step 2
    FormVal = fields(i+1)
    typeArray = Split(columns(i+1),",")
    Delim = typeArray(0)
    If (Delim = "none") Then Delim = ""
    AltVal = typeArray(1)
    If (AltVal = "none") Then AltVal = ""
    EmptyVal = typeArray(2)
    If (EmptyVal = "none") Then EmptyVal = ""
    If (FormVal = "") Then
    FormVal = EmptyVal
    Else
    If (AltVal <> "") Then
    FormVal = AltVal
    ElseIf (Delim = "'") Then  ' escape quotes
    FormVal = "'" & Replace(FormVal,"'","''") & "'"
    Else
    FormVal = Delim + FormVal + Delim
    End If
    End If
    If (i <> LBound(fields)) Then
    tableValues = tableValues & ","
    dbValues = dbValues & ","
    End if
    tableValues = tableValues & columns(i)
    dbValues = dbValues & FormVal
  Next
  editQuery = "insert into " & editTable & " (" & tableValues & ") values (" & dbValues & ")"

'Response.Write editQuery

'Response.End
  If (Not abortEdit) Then
    Set editCmd = Server.CreateObject("ADODB.Command")
    editCmd.ActiveConnection = editConnection
    editCmd.CommandText = editQuery
    editCmd.Execute
    editCmd.ActiveConnection.Close

    If (editRedirectUrl <> "") Then
    Response.Redirect(editRedirectUrl)
    End If
  End If

End If
%>

Edited by - Astralis on 12 December 2004 20:57:25
Go to Top of Page

dayve
Forum Moderator

USA
5820 Posts

Posted - 12 December 2004 :  19:06:02  Show Profile  Visit dayve's Homepage
ahhh, the dreaded bloated code that DW spits out... I would apply the function after this line:
FormVal = "'" & Replace(FormVal,"'","''") & "'"
FormVal = CleanText(FormVal)


CleanText equals the name of your function.

You can eliminate the line above it if your CleanText function takes care of the single quote issues.



Edited by - dayve on 12 December 2004 19:09:29
Go to Top of Page

Astralis
Senior Member

USA
1218 Posts

Posted - 12 December 2004 :  19:10:56  Show Profile  Send Astralis a Yahoo! Message
Thanks dayve! You and everyone here are always very helpful.
Go to Top of Page

Astralis
Senior Member

USA
1218 Posts

Posted - 12 December 2004 :  20:08:13  Show Profile  Send Astralis a Yahoo! Message
Well, that code is not likeing the replace function. When I try to update the DB, I get this error:


Microsoft JET Database Engine error '80040e14'

Syntax error (missing operator) in query expression 'þParliamentary Glossaryþ'. I'm not sure why the red is getting converted.

/admin/admin_update.asp, line 89

The "Parliamentary Glossary" is the title to the article and I can see that the replace function is somehow replacing characters in the update query. Do you know why?

Edited by - Astralis on 12 December 2004 20:09:43
Go to Top of Page

dayve
Forum Moderator

USA
5820 Posts

Posted - 12 December 2004 :  20:27:54  Show Profile  Visit dayve's Homepage
can you post a text version of admin_update.asp and your CleanText function?

Go to Top of Page

Astralis
Senior Member

USA
1218 Posts

Posted - 12 December 2004 :  20:56:22  Show Profile  Send Astralis a Yahoo! Message
Dayve,

Yes. I'll do that. I do want to figure out how to do that. But, first. I should tell you the work-around that I did. I don't understand it. I remembered that I use the system on a different site and all the characters come through without any problem. But, for some reason on this site that I'm working on, it didn't work. So, I looked at the Meta Tags to see what the difference was because that's the only explaination.

On the good site, it shows this:

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">


On the bas site, is shows this:

<META http-equiv=Content-Type content="text/html; charset=ISO-8859-15">


So, I replaced the bad with the good and it works! I don't understand it and I wonder if it will work on other computers. Can you explain why it works and if this can be a permanent work-around?
Go to Top of Page

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 13 December 2004 :  04:54:21  Show Profile  Visit D3mon's Homepage
I think this is what you're looking for:

'replaces non-sgml characters e.g. when content copy/pasted in from MS Word
strResult = replace(strResult,chr(133),"#8230;")
strResult = replace(strResult,chr(134),"#8224;")
strResult = replace(strResult,chr(135),"#8225;")
strResult = replace(strResult,chr(136),"#710;")
strResult = replace(strResult,chr(139),"#8249;")
strResult = replace(strResult,chr(145),"#8216;")
strResult = replace(strResult,chr(146),"#8217;")
strResult = replace(strResult,chr(147),"#8220;")
strResult = replace(strResult,chr(148),"#8221;")
strResult = replace(strResult,chr(150),"#8211;")
strResult = replace(strResult,chr(151),"#8212;")
strResult = replace(strResult,chr(152),"#732;")
strResult = replace(strResult,chr(153),"#8482;")
strResult = replace(strResult,chr(155),"#8250;")


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"
Go to Top of Page

Astralis
Senior Member

USA
1218 Posts

Posted - 13 December 2004 :  17:12:55  Show Profile  Send Astralis a Yahoo! Message
Thanks D3mon. Will this be used to input data in the database or to read it from the database? Do you recommend I keep this: "charset=windows-1252" on the admin page?
Go to Top of Page

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 13 December 2004 :  17:50:41  Show Profile  Visit D3mon's Homepage
This would be run on the input data before it is entered into the DB.

Stick with the: charset=ISO-8859-15 - You can't assume your site will always be viewed using a Windows-based browser.


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.26 seconds. Powered By: Snitz Forums 2000 Version 3.4.07