For future reference using explode and counting the words is not the correct
way to do this.  Your array could be huge, and if you have multiple requests
to the page this would be a horrible idea.  I believe the correct way to do
this is to use MySQL inherent function SUBSTRING_INDEX(str,delim,count)
So for example:

SELECT SUBSTRING_INDEX(column_name, ' ', 20) FROM table_name

would return the first 20 words.  The php way is over-doing it.  If you can
perform the logic in your mysql query, you should.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>From MySQL manual:
http://www.mysql.com/doc/S/t/String_functions.html

SUBSTRING_INDEX(str,delim,count)
Returns the substring from string str before count occurrences of the
delimiter delim. If count is positive, everything to the left of the final
delimiter (counting from the left) is returned. If count is negative,
everything to the right of the final delimiter (counting from the right) is
returned:
mysql> select SUBSTRING_INDEX('www.mysql.com', '.', 2);
        -> 'www.mysql'
mysql> select SUBSTRING_INDEX('www.mysql.com', '.', -2);
        -> 'mysql.com'

This function is multi-byte safe.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Hope this helps!

Robert V. Zwink
DAID Development LLC
http://www.zwink.net/daid.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to