After 3 days about 10 hours I have written a function for the forum that will split long strings by placing line breaks into them.
The difficult part wasn't stripping the HTML the problem was splitting long strings at every xx length.
The there was the problem of links if they contained the same text in the href link part as the displayed text both would be changed using the replace fuction. So I have to replace all href HTML tags with a code palcing both original HTML link and code into a two dimesional array to place back into the message at the end so that the HTML tag part of the link was not effected.
Anyway heres the function that needs to be placed in the functions_filter.asp file and called to from the post_message.asp file.
[code]'******************************************
'*** Split long text strings ***
'******************************************
'Function to strip out long words, long rows of chars, and long text lines from text
Private Function removeLongText(ByVal strMessageInput)
Dim lngMessagePosition 'Holds the message position
Dim intHTMLTagLength 'Holds the length of the HTML tags
Dim strHTMLMessage 'Holds the HTML message
Dim strTempMessageText 'Temp store for the message input
Dim strTempPlainTextWord 'Holds the plain text word
Dim saryPlainTextWord 'Array holding the plain text words
Dim sarySplitTextWord() 'Array holding the plain text word that has been split
Dim lngSplitPlainTextWordLoop 'Loop counter for looping through the pain text split word
Dim strTempOutputMessage 'Outputted string
Dim intWordSartPos 'Holds the location in the word to start the split
Dim saryHTMLlinks() 'Holds links from the message and thier corrisponding code
Dim strHTMLlinksCode 'Holds the code that is replaced the links with
Dim lngLoopCounter 'loop counter to count the number of HTML links in meesage
Dim blnHTMLlink 'Set to true if there is a link in the message body
Const intMaxWordLength = 60 'Holds the max word lentgh (can't be below 22 or will mess up the link code placed into messages)
'Initliase variables
lngLoopCounter = 0
blnHTMLlink = False
'Place the message input into a temp store
strTempMessageText = strMessageInput
strTempOutputMessage = strMessageInput
'**********************************
'**** Strip HTML from message *****
'**********************************
'Loop through each character in the post message
For lngMessagePosition = 1 to CLng(Len(strMessageInput))
'If this is the end of the message then save some process time and jump out the loop
If Mid(strMessageInput, lngMessagePosition, 1) = "" Then Exit For
'If an HTML tag is found then jump to the end so we can strip it
If Mid(strMessageInput, lngMessagePosition, 1) = "<" Then
'Get the length of the HTML tag
intHTMLTagLength = (InStr(lngMessagePosition, strMessageInput, ">", 1) - lngMessagePosition)
'If the end of the HTML string is in error then set it to the number of characters being passed
If intHTMLTagLength < 0 Then intHTMLTagLength = CLng(Len(strTempMessageText))
'Place the HTML tag back into the temporary message store
strHTMLMessage = Mid(strMessageInput, lngMessagePosition, intHTMLTagLength + 1)
'***************************************** *****
'**** Remove links so they aren't changed *****
'***************************************** *****
'See if the HTML tag is a link, if so replace with a code so it is not changed when spliting long chars
If InStr(1, strHTMLMessage, "href", 1) Then
'Add 1 to the loop counter
lngLoopCounter = lngLoopCounter + 1
'Redim the array, use preserve to keep the old array parts
ReDim Preserve saryHTMLlinks(2,lngLoopCounter)
'Create a code to replace the link with in original string
strHTMLlinksCode = " **/**WWFlink00" & lngLoopCounter & "**\** "
'Place the code and the original link into the array
saryHTMLlinks(1,lngLoopCounter) = strHTMLlinksCode
saryHTMLlinks(2,lngLoopCounter) = strHTMLMessage
'Rpleace the HTML tag with the new code that is saved in array
strTempOutputMessage = Replace(strTempOutputMessage, strHTMLMessage, strHTMLlinksCode, 1, -1, 0)
'A link is found so set the link found variable to true
blnHTMLlink = True
End If
'***************************************** **********
'Strip the HTML
strTempMessageText = Replace(strTempMessageText, strHTMLMessage, " ", 1, -1, 0)
End If
Next
'********************************************
'**** Check for and remove long strings *****
'********************************************
'Now we have just the text (no HTML) in plain text variable see if any of the text strings in it are over 30 chars in length
saryPlainTextWord = Split(Trim(strTempMessageText), " ")
'Loop through all the words till they are shortened
For lngLoopCounter = 0 To UBound(saryPlainTextWord)
'If the text string length is more than the max word length then place spaces in the text string
If Len(saryPlainTextWord(lngLoopCounter)) > intMaxWordLength Then
'Redim the array (don't use preserve as we want to loose the last data in the array)
Redim sarySplitTextWord(CInt(Len(saryPlainTextWord(lngLoopCounter) )/intMaxWordLength+1))
'Initiliase variable
intWordSartPos = 1
'Loop through all the splits in the word
For lngSplitPlainTextWordLoop = 1 To UBound(sarySplitTextWord)
'Place the split word into the array
sarySplitTextWord(lngSplitPlainTextW ordLoop) = Mid(saryPlainTextWord(lngLoopCounter), intWordSartPos, intMaxWordLength)
'Add max word length to the start position
intWordSartPos = intWordSartPos + intMaxWordLength
Next
'Place the split up long text string back together in one variable with spaces at the max word length
strTempPlainTextWord = Join(sarySplitTextWord, " ")
'Place the split up word back into the orginal message
strTempOutputMessage = Replace(strTempOutputMessage, saryPlainTextWord(lngLoopCounter), strTempPlainTextWord, 1, -1, 0)
End If