bitandblack/word-wrapper

Wrapping words for a perfect typography

2.0.0 2024-04-12 10:11 UTC

This package is auto-updated.

Last update: 2024-04-12 10:15:46 UTC


README

PHP from Packagist Codacy Badge Latest Stable Version Total Downloads License

Bit&Black Word Wrapper

Wrapping text for a perfect typography.

Installation

This library is made for the use with Composer. Add it to your project by running $ composer require bitandblack/word-wrapper.

Usage

These wrappers are available:

  • LinesWrapper: This class divides a text to reach a given number of lines.
  • MaxLengthWrapper: This class wraps a text when a lines reaches the maximum length of characters.

These outputs are available:

  • CSSOutput: This class uses <span> to divide the lines. Each span has class="word-wrapper-line" which you can use to define a wrap by your own. For example white-space: nowrap is very useful here. It's possible to customize the tag.
  • HTMLOutput: This class uses <br> to wrap into new lines. It's possible to customize the tag.
  • CustomOutput: This class needs to know your custom string. This is the second parameter.

Example

This example makes use of the LinesWrapper and the HTMLOutput.

<?php 

use BitAndBlack\WordWrapper\Output\HTMLOutput;
use BitAndBlack\WordWrapper\Wrapper\LinesWrapper;

$sentence = 'The Lord of the Rings';
$wrapper = new LinesWrapper(2, $sentence);
echo new HTMLOutput($wrapper);

This will echo The Lord of <br>the Rings.

Help

If you have questions feel free to contact us under hello@bitandblack.com.

Further information about Bit&Black can be found under www.bitandblack.com.