Visual Basic 6 function "nl2br"

Go back

Below you'll find the source for the Visual Basic 6 function nl2br.

Attribute VB_Name = "modNl2br"
' This function is downloaded from:
' http://www.stefanthoolen.nl/archive/vb6-functions/
' 
' You may freely distribute this file but please leave all comments, including this one, in it.
' 
' @Author Stefan Thoolen <mail@stefanthoolen.nl>

Option Explicit

''
' Inserts HTML line breaks before all newlines in a string
' Same syntax as the PHP function 'nl2br'
' See also: http://www.php.net/manual/en/function.nl2br.php
' @param    String  tstr        The normal string
' @return   String              A string containing <br />-tags
' @author   Stefan Thoolen <mail@stefanthoolen.nl>
Public Function nl2br(tstr As String) As String
    Dim ret As String, i As Integer, s As String
    For i = 1 To Len(tstr)
    	s = Mid(tstr, i, 1)
        If s = Chr(13) Then s = ""
        If s = Chr(10) Then s = "<br />" & Chr(10)
        ret = ret & s
    Next i
    nl2br = ret
End Function