If you want long strings to be connected sequentially inside the boundary container, I think you can do this by inserting space characters without spaces ( ​ or \xe2\x80\x8b ) between each letter of the orignial string . This will have a wrapping effect, as if each character was its own word, but without displaying spaces to the end user. This can cause problems with text search or indexing of the final product, but it should perform the task reliably from an aesthetic point of view.
Thus:
testtestetstetstetstetstettstetstetstetstetstetstetstetstetstetstets
becomes
t​e​s​t​t​e​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​t​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​s​t​e​t​s
(which displays: "testtssttttttttttttt test t t t t t t t t t t t t t t t t t t t t t et s ")
So, if you wrap it, it will be exactly bound to the borders of its container. Here is a scenario of this as an example .
Just write a PHP script to encode the line and insert a space:
$string="testtestetstetstetstetstettstetstetstetstetstetstetstetstetstetstets"; $new_string = ""; for($i=0;$i<strlen($string);$i++){ if ($string[$i]==' ' || $string[$i+1]==' '){ //if it is a space or the next letter is a space, there no reason to add a break character continue; } $new_string .= $string[$i]."​"; } echo $new_string
This is a particularly nice solution because, unlike wordwrap() , it is automatically configured for fonts of non-fixed widths (which basically makes up 99% of the fonts used).
Again, if you want the PDF file to be searchable, this is not a good approach, but it will make it look the way you want.
Ben d
source share