Nl2br
2 min read
Jun 2, 2026
---
title: nl2br
autoseo:
enabled: true
theme: learn2
child_type: default
admin:
children_display_order: collection
visible: true
---
nl2br — Inserts HTML line breaks before all newlines in a string
<?php
$tplix->assign('articleTitle',
"Sun or rain expected\ntoday, dark tonight"
);
Basic Usage:
{$article|nl2br}
Returns string with
or
inserted before all newlines (\r\n, \n\r, \n and \r).
| Parameter | Type | Required | Description |
|---|---|---|---|
| 1 | bool | No | true, Whether to use XHTML compatible line breaks or not. |
Where the template is:
{$articleTitle|nl2br} # renders: Sun or rain expected<br />today, dark tonight
{$articleTitle|nl2br:true} # renders: Sun or rain expected<br />today, dark tonight
Leave a Comment