bitandblack/word-wrapper

Wrapping words for a perfect typography

0.1.1 2019-11-16 20:29 UTC

This package is auto-updated.

Last update: 2020-02-16 21:08:41 UTC


README

PHP from Packagist Codacy Badge Latest Stable Version Total Downloads License composer.lock

Word Wrapper

Wrapping words for a perfect typography.

Installation

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

Usage

This wrappers are available:

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

This 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 word-wrapper@bitandblack.com.