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 ' {{$Q$}}
Replacing " with {{$QQ$}}
Replacing \ with {{$BS$}}
Replacing / with {{$FS$}}
Replacing > with {{$GT$}}
Replacing < with {{$LT$}}
And back

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

Function ANma_HTML2DB(strHTML)
 ' Convert string from HTML to be saved safly into DB
 '  Replacing {{$Q$}} with '
 '  Replacing {{$QQ$}} with "
 '  Replacing {{$BS$}} with \
 '  Replacing {{$FS$}} with /
 '  Replacing {{$GT$}} with >
 '  Replacing {{$LT$}} with <
 Rett      = Replace(strHTML, "'", "{{$Q$}}")
 Rett      = Replace(Rett, """", "{{$QQ$}}")
 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_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 <
 '
 Rett      = Replace(strDB, "{{$Q$}}", "'")
 Rett      = Replace(Rett, "{{$QQ$}}", """")
 Rett      = Replace(Rett, "{{$BS$}}", "\")
 Rett      = Replace(Rett, "{{$FS$}}", "/")
 Rett      = Replace(Rett, "{{$GT$}}", ">")
 Rett      = Replace(Rett, "{{$LT$}}", "<")
 Rett      = Replace(Rett, "", "")
 ANma_DB2HTML   = Rett
End Function

strHTML
or
strDB

Views 147 Downloads 71

'db', 'convert', 'replace', 'substitute', 'html', 'removehtml', 'removehtmltag', 'str2db', '2db', 'safe', 'save', 'tag', 'tags', 'app2db', 'db2str'

ANmarAmdeen
443
Attachments
Texts + Strings Classic ASP
Revisions

v1.0