HTML: Special Characters

Feb 3, 2012 at 1:38 AM

Does Foxpro have a function to convert special chars on HTML code

http://www.utexas.edu/learn/html/spchar.html

 

For example Düsseldorf will transformed in Düsseldorf

Any tips ?

 

Coordinator
Feb 3, 2012 at 4:00 AM
Edited Feb 3, 2012 at 4:09 AM

 

Seems to be a good article:

http://www.west-wind.com/presentations/foxunicode/foxunicode.asp

--------------------

oUtil=NEWOBJECT('AVFPutilities')
lcHTMLout=oUtil.URLEncode("Düsseldorf") 

works for URL encoding

There is also an

oHTML.htmlencode(string) but that doesn't seem to cover those special characters:

FUNCTION htmlencode
PARAMETERS lcString,decode
LOCAL ARRAY laEncoding[4,2]
laEncoding[1,1] = "&"
laEncoding[1,2] = "&"
laEncoding[2,1] = ["]
laEncoding[2,2] = """
laEncoding[3,1] = "<"
laEncoding[3,2] = "&lt;"
laEncoding[4,1] = ">"
laEncoding[4,2] = "&gt;"

FOR lnIndex = 1 TO ALEN(laEncoding,1)
    IF decode
        lcString = STRTRAN(lcString,laEncoding[lnIndex,2],laEncoding[lnIndex,1])
    ELSE
        lcString = STRTRAN(lcString,laEncoding[lnIndex,1],laEncoding[lnIndex,2])
    ENDIF
NEXT
RETURN lcString
ENDFUNC

Feb 4, 2012 at 11:38 AM

I did a expanded version on put on main prg, I psot here to share with others that have similar problems, Due to the extreme importance of this routine I would sugest that include on the default main prg

FUNCTION htmlencode
PARAMETERS lcString

LOCAL ARRAY laEncoding[51,2]
laEncoding[1,1] = "&"
laEncoding[1,2] = "&amp;"
laEncoding[2,1] = ["]
laEncoding[2,2] = "&quot;"
laEncoding[3,1] = "<"
laEncoding[3,2] = "&lt;"
laEncoding[4,1] = ">"
laEncoding[4,2] = "&gt;"
laEncoding[5,1] = "±"
laEncoding[5,2] = "&plusmn;"
laEncoding[6,1] = "€"
laEncoding[6,2] = "&euro;"
laEncoding[7,1] = "£"
laEncoding[7,2] = "&pound;"
laEncoding[8,1] = "¥"
laEncoding[8,2] = "&yen;"
laEncoding[9,1] = "á"
laEncoding[9,2] = "&aacute;"
laEncoding[10,1] = "Á"
laEncoding[10,2] = "&Aacute;;"
laEncoding[11,1] = "à"
laEncoding[11,2] = "&agrave;"
laEncoding[12,1] = "À"
laEncoding[12,2] = "&Agrave;"
laEncoding[13,1] = "â"
laEncoding[13,2] = "&acirc;"
laEncoding[14,1] = "Â"
laEncoding[14,2] = "&Acirc;"
laEncoding[15,1] = "ã"
laEncoding[15,2] = "&atilde;"
laEncoding[16,1] = "Ã"
laEncoding[16,2] = "&Atilde;"
laEncoding[17,1] = "ç"
laEncoding[17,2] = "&ccedil;"
laEncoding[18,1] = "Ç"
laEncoding[18,2] = "&Ccedil;"
laEncoding[19,1] = "é"
laEncoding[19,2] = "&eacute;"
laEncoding[20,1] = "É"
laEncoding[20,2] = "&Eacute;"
laEncoding[21,1] = "è"
laEncoding[21,2] = "&egrave;"
laEncoding[22,1] = "È"
laEncoding[22,2] = "&Egrave;"
laEncoding[23,1] = "ê"
laEncoding[23,2] = "&ecirc;"
laEncoding[24,1] = "Ê"
laEncoding[24,2] = "&Ecirc;"
laEncoding[25,1] = "ì"
laEncoding[25,2] = "&igrave;"
laEncoding[26,1] = "Ì"
laEncoding[26,2] = "&Igrave;"
laEncoding[27,1] = "î"
laEncoding[27,2] = "&icirc;"
laEncoding[28,1] = "Î"
laEncoding[28,2] = "&Icirc;"
laEncoding[29,1] = "ó"
laEncoding[29,2] = "&oacute;"
laEncoding[30,1] = "Ò"
laEncoding[30,2] = "&Oacute;"
laEncoding[31,1] = "ò"
laEncoding[31,2] = "&ograve;"
laEncoding[32,1] = "Ò"
laEncoding[32,2] = "&Ograve;"
laEncoding[33,1] = "ô"
laEncoding[33,2] = "&ocirc;"
laEncoding[34,1] = "Ô"
laEncoding[34,2] = "&Ocirc;"
laEncoding[35,1] = "ø"
laEncoding[35,2] = "&oslash;"
laEncoding[36,1] = "Ø"
laEncoding[36,2] = "&Oslash;"
laEncoding[37,1] = "õ"
laEncoding[37,2] = "&otilde;"
laEncoding[38,1] = "Õ"
laEncoding[38,2] = "&Otilde;"
laEncoding[39,1] = "ß"
laEncoding[39,2] = "&szlig"
laEncoding[40,1] = "ú"
laEncoding[40,2] = "&ugrave;"
laEncoding[41,1] = "Ù"
laEncoding[41,2] = "&Ugrave;"
laEncoding[42,1] = "–"
laEncoding[42,2] = "&ndash;"
laEncoding[43,1] = "—"
laEncoding[43,2] = "&mdash;"
laEncoding[44,1] = '"'
laEncoding[44,2] = "&quot;"
laEncoding[45,1] = '“'
laEncoding[45,2] = "&ldquo;"
laEncoding[46,1] = '”'
laEncoding[46,2] = "&rdquo;"
laEncoding[47,1] = "«"
laEncoding[47,2] = "&laquo;"
laEncoding[48,1] = "»"
laEncoding[48,2] = "&raquo;;"
laEncoding[49,1] = "µ"
laEncoding[49,2] = "&micro;"
laEncoding[50,1] = "´"
laEncoding[50,2] = "&#180;"
laEncoding[51,1] = "`"
laEncoding[51,2] = "&#96;"
 

FOR lnIndex = 1 TO ALEN(laEncoding,1)
    lcString = STRTRAN(lcString,laEncoding[lnIndex,2],laEncoding[lnIndex,1])
NEXT
RETURN lcString
ENDFUNC

 

Coordinator
Feb 4, 2012 at 6:33 PM
Edited Feb 4, 2012 at 6:34 PM

So this works correctly for you now?  I can add it to Activevfp.prg in the next release to take the place of the existing HTMLencode method.

Thanks!!