ANma_HTML2DB + ANma_DB2HTML + ...

Convert HTML text into DB-safe string, by converting some characters as below.
Cannot believe that I do not have this here before now.
Replacing ' with {{$Q$}}
Replacing " with {{$QQ$}}
Replacing \ with {{$BS$}}
Replacing / with {{$FS$}}
Replacing > with {{$GT$}}
Replacing < with {{$LT$}}
Replacing Enter (or
) with {
}
And back

Those two has t be used together everytime we read from or save into DB

Edit 2020-08-07: Added ANma_DB2Str and ANma_Str2DB2

CodeFunctionName
What is this?

Public

Tested

Original Work
Function ANma_HTML2DB(strHTML)
    ' Convert string from HTML to be saved safely into DB
    '        Replacing {{$Q$}} with '
    '        Replacing {{$QQ$}} with "
    '        Replacing {
} with <br/ >
    '        Replacing {{$BS$}} with \
    '        Replacing {{$FS$}} with /
    '        Replacing {{$GT$}} with >
    '        Replacing {{$LT$}} with <
    Rett                        = Replace(strHTML, "'", "{{$Q$}}")
    Rett                        = Replace(Rett, """", "{{$QQ$}}")
    Rett                        = Replace(Rett, " <br/ >", "{
}")
    Rett                        = Replace(Rett, "\", "{{$BS$}}")
    Rett                        = Replace(Rett, "/", "{{$FS$}}")
    Rett                        = Replace(Rett, " >", "{{$GT$}}")
    Rett                        = Replace(Rett, " <", "{{$LT$}}")
    Rett                        = Replace(Rett, "", "")
    ANma_HTML2DB            = Rett
End Function
Function ANma_Str2DB(strHTML)
    ' Convert string from String to be saved safely into DB
    '        Replacing {{$Q$}} with '
    '        Replacing {{$QQ$}} with "
    '        Replacing {
} with Enter
    '        Replacing {{$BS$}} with \
    '        Replacing {{$FS$}} with /
    '        Replacing {{$GT$}} with >
    '        Replacing {{$LT$}} with <
    Rett                        = Replace(strHTML, "'", "{{$Q$}}")
    Rett                        = Replace(Rett, """", "{{$QQ$}}")
    Rett                        = Replace(Rett, vbcrlf, "{
}")
    Rett                        = Replace(Rett, "\", "{{$BS$}}")
    Rett                        = Replace(Rett, "/", "{{$FS$}}")
    Rett                        = Replace(Rett, " >", "{{$GT$}}")
    Rett                        = Replace(Rett, " <", "{{$LT$}}")
    Rett                        = Replace(Rett, "", "")
    ANma_Str2DB                = Rett
End Function
Function ANma_DB2HTML(strDB)
    ' Convert string from DB (converted through ANma_HtmL2DB, into its HTML value
    '        Replacing {{$Q$}} with '
    '        Replacing {{$QQ$}} with "
    '        Replacing {{$BS$}} with \
    '        Replacing {{$FS$}} with /
    '        Replacing {{$GT$}} with >
    '        Replacing {{$LT$}} with <
    '        Replacing {
} with <br/ >
    '
    Rett                        = Replace(strDB, "{{$Q$}}", "'")
    Rett                        = Replace(Rett, "{{$QQ$}}", """")
    Rett                        = Replace(Rett, "{
}", " <br/ >")
    Rett                        = Replace(Rett, "{{$BS$}}", "\")
    Rett                        = Replace(Rett, "{{$FS$}}", "/")
    Rett                        = Replace(Rett, "{{$GT$}}", " >")
    Rett                        = Replace(Rett, "{{$LT$}}", " <")
    Rett                        = Replace(Rett, "", "")
    ANma_DB2HTML            = Rett
End Function
Function ANma_DB2Str(strDB)
    ' Convert string from DB (converted through ANma_HtmL2DB, into its string values
    '        Replacing {{$Q$}} with '
    '        Replacing {{$QQ$}} with "
    '        Replacing {{$BS$}} with \
    '        Replacing {{$FS$}} with /
    '        Replacing {{$GT$}} with >
    '        Replacing {{$LT$}} with <
    '        Replacing {
} with Enter
    '
    Rett                        = Replace(strDB, "{{$Q$}}", "'")
    Rett                        = Replace(Rett, "{{$QQ$}}", """")
    Rett                        = Replace(Rett, "{
}", vbcrlf)
    Rett                        = Replace(Rett, "{{$BS$}}", "\")
    Rett                        = Replace(Rett, "{{$FS$}}", "/")
    Rett                        = Replace(Rett, "{{$GT$}}", " >")
    Rett                        = Replace(Rett, "{{$LT$}}", " <")
    Rett                        = Replace(Rett, "", "")
    ANma_DB2Str                = Rett
End Function

strHTML
or
strDB

Views 3,045

Downloads 1,113

CodeID
DB ID