First off, special thanks to Tek-Tips user jfriestman for the following code I wish to present as the basis for my question. His code take a string read from a DB and writes it to the screen by converting all of the line feeds to <br> tags. Very nice.
I want to add to the code by having the function remove any trailing <br> tags at the end of the string. This could be caused by a user adding extra line feeds in a <textarea> tag in a form.
Thanks jfriestman:
<%
Function PrepForHtml (strDirty)
Dim strClean
If IsNull(strDirty) OR Trim(strDirty) = "" Then
PrepForHTML = ""
Exit Function
End If
strClean = Trim(strDirty)
strClean = Replace(strClean, "<", "<", 1, -1 , 1)
strClean = Replace(strClean, ">", ">", 1, -1 , 1)
strClean = Replace(strClean, Chr(10), "<br>", 1, -1, 1)
PrepForHtml = strClean
End Function
%>
How to use?
<%
Dim sText
sText = PrepForHTML(Rs.Fields("myField"
.Value)
%>
This function would still return <br> tags at the end if the DB had them in there. So the question is:
How can one remove the trailing <br> chars within the string?
TRIM() does a nice job with the blank space char, so can someone create trimBR() for us here?
Many thanks,
Magnus
I want to add to the code by having the function remove any trailing <br> tags at the end of the string. This could be caused by a user adding extra line feeds in a <textarea> tag in a form.
Thanks jfriestman:
<%
Function PrepForHtml (strDirty)
Dim strClean
If IsNull(strDirty) OR Trim(strDirty) = "" Then
PrepForHTML = ""
Exit Function
End If
strClean = Trim(strDirty)
strClean = Replace(strClean, "<", "<", 1, -1 , 1)
strClean = Replace(strClean, ">", ">", 1, -1 , 1)
strClean = Replace(strClean, Chr(10), "<br>", 1, -1, 1)
PrepForHtml = strClean
End Function
%>
How to use?
<%
Dim sText
sText = PrepForHTML(Rs.Fields("myField"
%>
This function would still return <br> tags at the end if the DB had them in there. So the question is:
How can one remove the trailing <br> chars within the string?
TRIM() does a nice job with the blank space char, so can someone create trimBR() for us here?
Many thanks,
Magnus