Reputation: 400
I have a list item and the value of this string item comes from a php command, how would I limit the amount of characters in this li allowed on an actual line. E.g. say I had a variable
$foo = 'tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt'
then I have (in html)
<ul>
<li> <?php echo $foo; ?> </li>
</ul>
How would I make it so only (say) 7 characters were allowed on the line so instead of printing
tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
It would print something like
ttttttt
ttttttt
ttttttt
etc etc.
Upvotes: 0
Views: 102
Reputation: 20469
use css wordwrap:
<style>
ul {width:30px;}
li.wrap{word-wrap: break-word;}
</style>
<ul>
<li>ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff</li>
<li class="wrap">ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff</li>
</ul>
Live example:
Or if you want a php only solution use str_split
and implode
:
$a = 'fffffffffffffffffffffffffffffffffffffffffffffff';
echo implode(PHP_EOL, str_split($a, 7));
Here the constant PHP_EOL
is used to insert carriage returns every 7 chars. You could instead use a space ' '
or an html line break '<br>'
depending on requirements
Live example:
http://codepad.viper-7.com/iCbNJQ
Upvotes: 2
Reputation: 7240
$len = strlen($foo); $i = 0;
while($len>0){
echo substr($foo, $i, 7)."<br>";
$i += 7;
$len -=7;
}
Upvotes: 1