PHP Code:
Public Function WordWrap(ByVal strTextToBeWrapped As String, ByVal intMaxLineLength As Integer) As String
Dim strWrappedText As String
Dim intLengthOfInput As Integer
Dim intCurrentPosition As Integer
Dim intCurrentLineStart As Integer
Dim intPositionOfLastSpace As Integer
intLengthOfInput = Len(strTextToBeWrapped)
intCurrentPosition = 1
intCurrentLineStart = 1
Do While intCurrentPosition < intLengthOfInput
If Mid(strTextToBeWrapped, intCurrentPosition, 1) = " " Then
intPositionOfLastSpace = intCurrentPosition
End If
If intCurrentPosition = intCurrentLineStart + intMaxLineLength Then
strWrappedText = strWrappedText & Trim(Mid(strTextToBeWrapped, intCurrentLineStart, intPositionOfLastSpace - intCurrentLineStart + 1)) & vbCrLf
intCurrentLineStart = intPositionOfLastSpace + 1
Do While Mid(strTextToBeWrapped, intCurrentLineStart, 1) = " "
intCurrentLineStart = intCurrentLineStart + 1
Loop
End If
intCurrentPosition = intCurrentPosition + 1
Loop
strWrappedText = strWrappedText & Trim(Mid(strTextToBeWrapped, intCurrentLineStart)) & vbCrLf
strWrappedText = Replace(strWrappedText, vbCrLf, "<br />" & vbCrLf)
Return strWrappedText
End Function
Bookmarks