break
Summary
Returns the input string with all newlines converted to HTML breaks.
Usage
input|break()
Returns
A string with HTML breaks.
Description
This operator takes a string as input. It does not replace newline characters/sequences, but it does insert HTML break tags ( <br /> ) before all newlines in a string and returns a modified version of the input.
Examples
Example 1
{'The lazy
cat
jumps over
the quick rat.'|break()}The following output will be produced:
The lazy<br />cat<br />jumps over<br />the quick rat.
Contributors
- Balazs Halasy Maintainer
- Ester Heylen Updated Maintainer
- Paul Borgermans Commenter
- Gunnstein Lye Commenter
Comments (2 historical)
Written by readers of the earlier documentation sites, kept as they were.
The newlines are still in the output string
Paul Borgermans ·
.... which is a feature of the underlying nl2br php function.
See http://be.php.net/manual/en/function.nl2br.php
So to create for example a safe javascript string, this operator need to be patched.
Re: The newlines are still in the output string
Gunnstein Lye ·
One solution is to use this instead:
{'The lazycatjumps overthe quick rat.'|explode('\n')|implode('')}