Simple output wrapper for "tagged outputs" instead of wordwrap(). This solution is based on a StackOverflow
answer: https://stackoverflow.com/a/20434776/1476819 from user557597 (alias SLN).
(?:
# -- Words/Characters
( # (1 start)
(?> # Atomic Group - Match words with valid breaks
.{1,16} # 1-N characters
# Followed by one of 4 prioritized, non-linebreak whitespace
(?: # break types:
(?<= [^\S\r\n] ) # 1. - Behind a non-linebreak whitespace
[^\S\r\n]? # ( optionally accept an extra non-linebreak whitespace )
| (?= \r? \n ) # 2. - Ahead a linebreak
| $ # 3. - EOS
| [^\S\r\n] # 4. - Accept an extra non-linebreak whitespace
)
) # End atomic group
|
.{1,16} # No valid word breaks, just break on the N'th character
) # (1 end)
(?: \r? \n )? # Optional linebreak after Words/Characters
|
# -- Or, Linebreak
(?: \r? \n | $ ) # Stand alone linebreak or at EOS
)
- author Krisztián Ferenczi
- see https://stackoverflow.com/a/20434776/1476819
CloneableFinalInstantiable
Methods |
public __construct(bool $allowCutUrls = false) |
public wrap(string $text, int $width, string $break = ' ') : string |
Constants |
private Symfony |
private Symfony |
private Symfony |
Properties |
private bool $allowCutUrls |