Created
February 8, 2017 05:54
-
-
Save ronisaha/45a1498d960251ea2d38cd96c16bca62 to your computer and use it in GitHub Desktop.
PHP_WORDWRAP in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function wordwrap( str, width, brk, cut ) { | |
| brk = brk || '\n'; | |
| width = width || 75; | |
| cut = cut || false; | |
| if (!str) { return str; } | |
| var regex = '.{1,' +width+ '}(\\s|$)' + (cut ? '|.{' +width+ '}|.+$' : '|\\S+?(\\s|$)'); | |
| return str.match( new RegExp(regex, 'g') ).join( brk ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment