RE: [PHP] selecting words

From: Date: Wed, 08 Aug 2001 14:22:05 +0000
Subject: RE: [PHP] selecting words
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-61829@lists.php.net to get a copy of this message
If you are using MySQL use the function: SELECT SUBSTRING_INDEX(column_name, ' ', 100) FROM table_name would return the first 100 words. This is in the MySQL manual, this was also answered earier on the list. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Robert V. Zwink DAID Development LLC http://www.zwink.net/daid.php -----Original Message----- From: Jon Farmer [mailto:jonfarmer@enta.net] Sent: Wednesday, August 08, 2001 4:19 AM To: Alfredeen, Johan; 'Jamie Saunders' Cc: php-general@lists.php.net Subject: RE: [PHP] selecting words >There was a post earlier very similar to this. If you have a database, you >could use SELECT LEFT(mycolumn, 100) FROM mytable WHERE ... >Without a db, you can use the PHP substring function: >substr() Except that would return the first 100 characters and not the first 100 words as requested. To do this you would need to find the 100th space in the string and use everything before that. I would probably explode the string and loop through the first one hundred elements to reconstruct the string with the first one hundred words. Regards Jon Jon Farmer Systems Programmer Entanet International Ltd www.enta.net Tel 01952 428969 Mob 07968 524175 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#61829) next »