CSS Solution
You could set a height and do overflow hidden.
span {
display: inline-block;
border: black 1px solid;
width: 300px;
height: 40px;
overflow: hidden;
}
Example: http://jsfiddle.net/imoda/REs2Q/
PHP Solution
The server sided alternative is to use substr
<?php
$string = "Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision. But when I try to look at you, you scurry away. Are you shy, squiggly line? Why only when I ignore you, do you return to the center of my eye? Oh, squiggly line, it's alright, you are forgiven.";
echo charlimit($string, 100);
function charlimit($string, $limit) {
return substr($string, 0, $limit) . (strlen($string) > $limit ? "..." : '');
}
?>
Example: http://codepad.org/OetkaMh6
This will output 100 characters of the string then append ...
Trick with this is you'll have to change the number of characters to what works best for your situation. Because it's server sided, it won't know how many characters it takes in each scenario to trigger only one carriage return.
Alternatively, you can limit the number of words:
<?php
$string = "Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision. But when I try to look at you, you scurry away. Are you shy, squiggly line? Why only when I ignore you, do you return to the center of my eye? Oh, squiggly line, it's alright, you are forgiven.";
echo wordlimit($string, 20);
function wordlimit($string, $limit) {
$overflow = true;
$array = explode(" ", $string);
$output = '';
for ($i = 0; $i < $limit; $i++) {
if (isset($array[$i])) $output .= $array[$i] . " ";
else $overflow = false;
}
return trim($output) . ($overflow ? "..." : '');
}
?>
Example: http://codepad.org/WYJFPaD5
But it's the same thing, you have to tailor it to "best fit"
Hope that helps.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…