Kevin,

Your program certainly makes very good sense to me. 
However, 2 things i will need to ask you.. is that,
let's say i decide i want the first 4 words from the
record displayed.. for all the 4 rows i'm displaying..
where do i define that in your program?
And secondly, how do i make this program work on the
myrow[myfield] variable which will actually carry the
record from the database?

thanks,
Rahul
 
> I don't know how to do it within the SQL query.. or
> even if it's possible.
> But you can always gather the results as normal and
> build a function within
> php that chops up each line into words and uses the
> first few words as an
> abreviative text.  If you want the strings to be of
> uniform length (or to
> ensure a minimum length) then you could do something
> with the strlen() and
> strpos() functions.  This simple function that I
> wrote cares only about the
> number of words in the abreviation.  It's rather
> crude but you're welcome to
> use it if it helps you..
> 
> function abreviate_text($str, $num_words)
> {
>     // $str parameter must be an alpha numeric
> string
>     if (!is_string($str))
>         return false;
> 
>     // $num_words parameter must be a non-zero
> integer value
>     if (!is_integer($num_words) || $num_words == 0)
>         return false;
> 
>     // split the string on all single spaces
>     $words = explode(' ', $str);
> 
>     // build abreviated text..
>     $abr = array();
>     for($i=0; $i<$num_words; $i++)
>     {
>         $abr[] = $words[$i];
>     }
>     $abr = implode(' ', $abr);
>     $abr .= "...";
> 
>     return $abr;
> }
> 
> - Kevin
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to