I have a div which has a fluid width, thus I cannot predict its size in PHP. If someone enters a long string which isn't delimited by spaces anywhere, the browser will stretch the page, and that gets quite annoying rather quickly. I have tried to use the wordwrap
function for this, but I can never find the proper width and I am having issues with output.
Here's what I am trying, based on a comment left on the documentation page for wordwrap
:
<?php
//Using ​ here allows the browser to break the line of text, without the visual distraction.
$line = wordwrap($line, 10, "​", true);
?>
The comment goes on to explain how it's a Zero Width Space character, which will tell the browser it is free to break but doesn't show up.
I'm sure you can already see the two problems which have arisen. It will replace normal spaces with that zero width space as well, so I wind up with things like: This is atest.Hello,Stackoverflow! Thisought totrigger acouple ofbreaks.
I also coded a small bbcode parser for this, and it also breaks my html output since it cuts the tags.
On the plus side, incredibly long words are broken as expected!
I've tried setting various overflow properties on the div in CSS, but none of them function as expected.