You are here: Re: [DONE] Substr by words « PHP « IT news, forums, messages
Re: [DONE] Substr by words

Posted by James Benson on 10/29/05 22:41

Did you actually test that?


Even better version of your function,



<code>

$string = "one two three four";

echo substr($string, -4);
echo '...';

</code>



James




Danny wrote:
> Finally i found it (Google is god, you only have to ask the right question)
> function trim_text($text, $count){
> $text = str_replace(" ", " ", $text);
> $string = explode(" ", $text);
> for ( $wordCounter = 0; $wordCounter <= $count;wordCounter++ ){
> $trimed .= $string[$wordCounter];
> if ( $wordCounter < $count ){ $trimed .= " "; }
> else { $trimed .= "..."; }
> }
> $trimed = trim($trimed);
> return $trimed;
> }
>
> Usage
> ------------------------------------------------
> $string = "one two three four";
> echo trim_text($string, 3);
>
>
> ---------- Forwarded message ----------
> From: Danny <metalito@gmail.com>
> Date: Oct 29, 2005 1:36 PM
> Subject: Substr by words
> To: php-general@lists.php.net
>
> Hi,
> I need to extract 50 words more or less from a description field. How can i
> do that?. Substr, cuts the words. Is there any other way to that, without
> using and array? I mean and implemented function in PHP 4.x
> I´ve been googling around, but wordwrap, and substr is driving me mad...
> Thanks in advance
> Best Regards
>
> --
> dpc
>
>
> --
> dpc
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация