Re: [DONE] Substr by words

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, October 29, 2005 10:51 am, Minuk Choi wrote:
> function trim_text($text, $count)
> {
> 	$text = str_replace(" ", " ", $text);
> 	/*
> 	 * This is redundant; you are replacing all " " in $text with " "
> 	 *  maybe you meant
> 	 *   $text = trim($text); ?
> 	 */

It was probably replacing *TWO* spaces with one.

If so, it should really be in a while loop, because there could be 3
or more spaces in a row, and if the goal is only single-spaced
words...

//Replace 2 spaces with 1 until all words are single-spaced
while (strstr($text, '  ')) $text = str_replace('  ', ' ', $text);

PS

My post was doing 50 LETTERS, not 50 words.

So change 50 to 250 and call it done. :-)

Unless the word-count is really that critical...

-- 
Like Music?
http://l-i-e.com/artists.htm

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux