Forum Moderators: coopster
I have created a DIV that contains a text variable.
Looks something like this:
<div><?php echo($text);?></div>
One very important thing to point out is that the div is styled using CSS, and must have a specific width and height.
Above works great, except for when the text is very long. Different browsers handle the text overflow differently, but regardless of how they handle it, the output is not ideal.
What is preferred is if the text is split up, and put into multiple divs, like this:
<div><?php echo($text[1]);?></div>
<div><?php echo($text[2]);?></div>
Right now I am using something along those lines. My text is exploded based on spaces between the words. Then the number of words are counted.
I've set a standard of 100 words per div, and have written the following code:
$words=explode(" ",$text);
$c=count($words);
echo("<div>$words[0] ");
for($i=1;$i<=$c;$i++){
if($i%100!=0)echo("$words[$i] ");
if($i%100==0){echo("</div><div>$words[$i] ");}
}
echo("</div>");
This is satisfactory, but the thing is that sometimes 100 words are too few to fill up the div, and sometimes 100 words are too many for the div.
Is there a way to fill up the div with text until it is full, before creating and filling the next div?
To confound this issue more, I need to use a specific font, and this font does not have a fixed width.
Any help would be much appreciated.
Thanks
That said I'd recommend using a more flexible system, as the real difficulty is not to design something that works in one instance, but in many instances and permutations.