
September 24th, 2003, 02:34 PM
|
 |
Contributing User
|
|
Join Date: May 2003
Location: Tennessee
Posts: 1,355
Time spent in forums: < 1 sec
Reputation Power: 7
|
|
Check out http://us2.php.net/manual/en/function.wordwrap.php. There are any number of ways you could do this, but I hadn't run across this function before and thought I'd give it a shot. Something like the following code should work. I'm assuming for the sake of this example that your mysql column is in $str.
PHP Code:
$words=split("|",wordwrap($str,75,"|"));
print $words[0];
The wordwrap function returns your string cut on word boundaries with the second parameter as the max col count. The third parameter is the character you wish to cut your string with. So you can feed the results of wordwrap to split, splitting on the character you used to cut, and voila, you've got an array whose zero element is, in this case, not more than 75 characters wide.
You could also do something like the following:
PHP Code:
$words=split(" ",$str);
print join(" ",array_slice($words,0,25));
This code splits a string into its words and then prints the first 25 elements of the words array.
|