Re: [PHP] splitting text after 25 words

2001-08-08 Thread Justin French

Thanks to all who replied, this solution by Chris was bar far the
easiest to implement.

Really appreciate it :)


Chris Lambert wrote:

 $teaser = explode( , $article, 26));
 array_pop($teaser);
 $teaser = implode( , $teaser);


Justin French

-- 
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] splitting text after 25 words

2001-08-08 Thread Robert V. Zwink

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


-Original Message-
From: Justin French [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 08, 2001 7:25 AM
To: Chris Lambert; php
Subject: Re: [PHP] splitting text after 25 words


Thanks to all who replied, this solution by Chris was bar far the
easiest to implement.

Really appreciate it :)


Chris Lambert wrote:

 $teaser = explode( , $article, 26));
 array_pop($teaser);
 $teaser = implode( , $teaser);


Justin French

--
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] splitting text after 25 words

2001-08-08 Thread jose d lopez

someting i've used.

?php
$storywords = explode( , $storytext);

for ($i=0;$i25;$i++) {
 $teaser = $teaser .   . $storywords[$i];
}
?

? echo $teaser...;?


At 03:57 PM 8/8/2001 +1100, Justin French wrote:
Hi all,

I'd like to split a text block at 25 words, as a teaser for the full
article.  Now I know how to split at a certain character, but i don't
want a half word or anything, so I want (i guess) to hunt for the 25th
occurence of   (a space), and split $text into two new variables,
$text_a and $text_b.

Then I'll prolly want append something like ... click here to read
more on the end of $text_a.

Seems easy enough, but I can't see anything in the manual about
splitting on a numbered occurence of a string (but I could be looking
in the wrong spot :)

Running PHP4 BTW



Thanks heaps in advance
Justin French

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



_
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


-- 
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] splitting text after 25 words

2001-08-07 Thread Chris Lambert

$teaser = explode( , $article, 26));
array_pop($teaser);
$teaser = implode( , $teaser);

/* Chris Lambert, CTO - [EMAIL PROTECTED]
WhiteCrown Networks - More Than White Hats
Web Application Security - www.whitecrown.net
*/

- Original Message - 
From: Justin French [EMAIL PROTECTED]
To: php [EMAIL PROTECTED]
Sent: Wednesday, August 08, 2001 12:57 AM
Subject: [PHP] splitting text after 25 words


| Hi all,
| 
| I'd like to split a text block at 25 words, as a teaser for the full 
| article.  Now I know how to split at a certain character, but i don't 
| want a half word or anything, so I want (i guess) to hunt for the 25th 
| occurence of   (a space), and split $text into two new variables,
| $text_a and $text_b.
| 
| Then I'll prolly want append something like ... click here to read 
| more on the end of $text_a.
| 
| Seems easy enough, but I can't see anything in the manual about 
| splitting on a numbered occurence of a string (but I could be looking
| in the wrong spot :)
| 
| Running PHP4 BTW
| 
| 
| 
| Thanks heaps in advance
| Justin French
| 
| -- 
| 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] splitting text after 25 words

2001-08-07 Thread karthik

Hi,

Best way i guess would be traverse the whole string and check for space.
Have a counter var which keeps count of the space. At the 25th occurence do
something like this -

$text_a = substr($text, 1, $i);

i assume that $i is the increment var in the loop.

$text_b = substr($text, $i+1);

This should give u the strings in 2 vars.

Now u can add anything with $text_aClick here .$text_b

Hope i was helpful,
Karthik.

- Original Message -
From: Justin French [EMAIL PROTECTED]
To: php [EMAIL PROTECTED]
Sent: Wednesday, August 08, 2001 10:27 AM
Subject: [PHP] splitting text after 25 words


 Hi all,

 I'd like to split a text block at 25 words, as a teaser for the full
 article.  Now I know how to split at a certain character, but i don't
 want a half word or anything, so I want (i guess) to hunt for the 25th
 occurence of   (a space), and split $text into two new variables,
 $text_a and $text_b.

 Then I'll prolly want append something like ... click here to read
 more on the end of $text_a.

 Seems easy enough, but I can't see anything in the manual about
 splitting on a numbered occurence of a string (but I could be looking
 in the wrong spot :)

 Running PHP4 BTW



 Thanks heaps in advance
 Justin French

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