GithubHelp home page GithubHelp logo

php-wordwrap's Introduction

PHP-WordWrap

GitHubphp-standard-styleGitHub top language

Word wrapping, with a few features.

  • force-break option
  • wraps hypenated words
  • multilingual - wraps any language that uses whitespace for word separation.
  • custom symbol wrap mode
  • chain call
  • multi-format return

Install

composer require kayw-geek/php-wordwrap

Synopsis

Wrap some text in a 20 character column.

> $wrap = new \KaywGeek\WordWrap();

> $text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";

> $result = $wrap->text($text)->width(20)->wrap();

result now looks like this:

Lorem ipsum dolor
sit amet,
consectetur
adipiscing elit, sed
do eiusmod tempor
incididunt ut labore
et dolore magna
aliqua.

By default, long words will not break. Unless you set the break option.

> $text = "https://github.com/kayw-geek/php-wordwrap"

> $wrap->text($text)->width(28)->break(false)->wrap();
  https://github.com/kayw-geek/php-wordwrap

> $wrap->text($text)->width(28)->break()->wrap();
  https://github.com/kayw-geek
  /php-wordwrap

Punctuation wrap mode

> $text = "Of course,the first example appears to be the nicest one (or perhaps the fourth),but you may find that being able to use empty expressions in for loops comes in handy in many occasions.";


> $wrap->text($text)->lfEnable()->wrap();

result

Of course,
the first example appears to be the nicest one (or perhaps the fourth),
but you may find that being able to use empty expressions in for loops comes in handy in many occasions.

Format data

> $text = "Of course,the first example appears to be the nicest one (or perhaps the fourth),but you may find that being able to use empty expressions in for loops comes in handy in many occasions.";

/**
* Format List
* \KaywGeek\WordWrap::FORMAT_JSON
* \KaywGeek\WordWrap::FORMAT_STRING
* \KaywGeek\WordWrap::FORMAT_ARRAY
*/
> $wrap->text($text)
    ->lfEnable()
    ->responseFormat(\KaywGeek\WordWrap::FORMAT_JSON)
    ->wrap();

Inspiration

wordwrapjs

php-wordwrap's People

Contributors

kayw-geek avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.