KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm going to make a word wrap algorithm in PHP. I want to split small chunks of text (short phrases) in n lines of maximum m characters ( n is not given, so there will be as much lines as needed). The peculiarity is that lines length (in characters) has to be much balanced as possible across lines. Example of input text: How to do things Wrong output (this is the normal word-wrap behavior), m=6 : How to do things Desired output, always m=6 : How to do things Does anyone have suggestions or guidelines on how to implement this function? Basically, I'm searching something for pretty print short phrases on two or three (as much as possible) equal length lines . Update : It seems I'm searching exactly for a Minimum raggedness word wrap algorithm . But I can't find any implementation in a real programming language (anyone, then I can convert it in PHP). Update 2 : I started a bounty for this. Is it possible that do not exist any public implementation of Minimum raggedness algorithm in any procedural language? I need something written in a way that can be translated into procedural instructions . All I can find now is just a bounch of (generic) equation that however need a optimal searching procedure. I will be grateful also for an implementation that can only approximate that optimal searching algorithm.
Tags (comma-separated)
Save Edits
Cancel