Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you want long strings to wrap consistently within a boundary container I think you should be able to accomplish this by <strong>inserting <a href="http://www.fileformat.info/info/unicode/char/200b/index.htm" rel="nofollow">zero-width space characters</a> (<code>&amp;#8203;</code> or <code>\xe2\x80\x8b</code>) between every letter of the orignial string</strong>. This will have the effect of wrapping as if every character was its own word, but without displaying the spaces to the end user. This may cause you trouble with text searches or indexing on the final product, but it should accomplish the task reliably from an aesthetic perspective.</p> <p>Thus:</p> <pre><code>testtestetstetstetstetstettstetstetstetstetstetstetstetstetstetstets </code></pre> <p>Becomes</p> <pre><code>t&amp;#8203;e&amp;#8203;s&amp;#8203;t&amp;#8203;t&amp;#8203;e&amp;#8203;s&amp;#8203;t&amp;#8203;e&amp;#8203;t&amp;#8203;s&amp;#8203;t&amp;#8203;e&amp;#8203;t&amp;#8203;s&amp;#8203;t&amp;#8203;e&amp;#8203;t&amp;#8203;s&amp;#8203;t&amp;#8203;e&amp;#8203;t&amp;#8203;s&amp;#8203;t&amp;#8203;e&amp;#8203;t&amp;#8203;t&amp;#8203;s&amp;#8203;t&amp;#8203;e&amp;#8203;t&amp;#8203;s&amp;#8203;t&amp;#8203;e&amp;#8203;t&amp;#8203;s&amp;#8203;t&amp;#8203;e&amp;#8203;t&amp;#8203;s&amp;#8203;t&amp;#8203;e&amp;#8203;t&amp;#8203;s&amp;#8203;t&amp;#8203;e&amp;#8203;t&amp;#8203;s&amp;#8203;t&amp;#8203;e&amp;#8203;t&amp;#8203;s&amp;#8203;t&amp;#8203;e&amp;#8203;t&amp;#8203;s&amp;#8203;t&amp;#8203;e&amp;#8203;t&amp;#8203;s&amp;#8203;t&amp;#8203;e&amp;#8203;t&amp;#8203;s&amp;#8203;t&amp;#8203;e&amp;#8203;t&amp;#8203;s </code></pre> <p>(which displays: "t&#8203;e&#8203;s&#8203;t&#8203;t&#8203;e&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s&#8203;t&#8203;e&#8203;t&#8203;s")</p> <p>So if you wrap it it will wrap exactly to the bounds of its container. <strong><a href="http://jsfiddle.net/cs7aW/" rel="nofollow">Here's a fiddle of it as an example</a></strong>.</p> <p>Just write a PHP script to loop though the string and insert the space:</p> <pre><code>$string="testtestetstetstetstetstettstetstetstetstetstetstetstetstetstetstets"; $new_string = ""; for($i=0;$i&lt;strlen($string);$i++){ if ($string[$i]==' ' || $string[$i+1]==' '){ //if it is a space or the next letter is a space, there's no reason to add a break character continue; } $new_string .= $string[$i]."&amp;#8203;"; } echo $new_string </code></pre> <p>This is a particularly nice solution, because unlike <code>wordwrap()</code>, it automatically adjusts for non-fixed-width fonts (which is basically 99% of fonts that are actually used).</p> <p>Again, if you need to resulting PDF to be searchable, this is not a good approach, but it will make it <em>look</em> like you want it to.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload