RE: [PHP] selecting words

2001-08-08 Thread Jon Farmer

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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] selecting words

2001-08-08 Thread Robert V. Zwink

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:[EMAIL PROTECTED]]
Sent: Wednesday, August 08, 2001 4:19 AM
To: Alfredeen, Johan; 'Jamie Saunders'
Cc: [EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
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]




RE: [PHP] selecting words

2001-08-07 Thread Alfredeen, Johan

Jamie,
  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()

Hope this helps,

Johan Alfredeen
www.pongworld.com


-Original Message-
From: Jamie Saunders [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 07, 2001 3:53 PM
To: [EMAIL PROTECTED]
Subject: [PHP] selecting words


Hi,

What I'd like to do is take a string (paragraph) of text consisting of say
500 words and display only the first 100 words.  Is there a function able to
do this?

Thanks.

Jamie



-- 
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]

-- 
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]