pacman, rainbows, and roller s
/ /

XtScript Function: br2nl and nl2br

Replace all newlines with HTML line breaks, or insert HTML line breaks before all newlines.

XtScript br2nl is a function of XtScript that will manipulate a string to replace all HTML line breaks (<br>) with newlines character (\n).

Otherwise, XtScript nl2br function will insert HTML line break tags (<br/>) before all newline characters. Notice that newline characters will not be deleted after the process.

XtScript br2nl and nl2br function basic syntax:

<!--parser:xtscript-->
	# Convert all HTML line break tags into newlines
	call br2nl $val=...; $is_xhtml=...

	# Insert HTML line break tags before all newlines
	call nl2br $val=...
<!--/parser:xtscript-->

Additional parameter on XtScript br2nl function:

  • $is_xhtml=...
    Value = 0 (false) or 1 (true).
    If $is_xhtml=1, we are telling the script to follow XHTML strict where unclosed line break tags (<br>) is not a valid line break thus will not be converted into newline character. Then $is_xhtml=0 is the reverse, where both closed (<br/>) and unclosed (<br>) line breaks will be replaced with newlines character.

Learn XtScript br2nl function from examples

Replace all HTML line breaks tag with newline characters.

- Code:
<!--parser:xtscript-->
	var $string = Are you sleeping <br/>Are you sleepping <br><br/>Brother John... <br/>Brother John...
	var $filter_br = call br2nl $val=$string; $is_xhtml=0

	print Original string: <br/>
	print <b>$string</b>

	print <br/><br/>

	print After br2nl: <br/>
	print <b>$filter_br</b>
<!--/parser:xtscript-->
- Result:
Original string:
Are you sleeping
Are you sleepping

Brother John...
Brother John...


After br2nl:
Are you sleeping Are you sleepping Brother John... Brother John...

Insert HTML line breaks before newlines found in a string.

- Code:
<!--parser:xtscript-->
	var $string = {{ <u>Hello visitors!</u>

	XtScript is the Xtgem's own server side scripting.
	There are not many similar services to Xtgem provide server side scripting.


	Or... there are? }}
	var $convert_newlines = call nl2br $val=$string

	print Original string: <br/>
	print <b> $string </b>
	print <br/><br/>

	print Converted newlines to line breaks: <br/>
	print <b> $convert_newlines </b>
<!--/parser:xtscript-->
- Result:
Original string:
Hello visitors! XtScript is the Xtgem's own server side scripting. There are not many similar services to Xtgem provide server side scripting. Or... there are?

Converted newlines to line breaks:
Hello visitors!

XtScript is the Xtgem's own server side scripting.
There are not many similar services to Xtgem provide server side scripting.


Or... there are?