Re: limiting characters
| From: | Michael P. Carel | Date: | Wed, 19 Feb 2003 02:49:40 +0000 |
| Subject: | Re: limiting characters | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-136107@lists.php.net to get a copy of this message | ||
thnks its working here
----- Original Message -----
From: "Justin French" <justin@indent.com.au>
To: "Michael P. Carel" <mikecarel@teamglac.com>; <php-general@lists.php.net>
Sent: Wednesday, February 19, 2003 8:09 AM
Subject: Re: [PHP] limiting characters
> Season to taste:
>
> <?
> function chopper($string,$length=20, $suffix="...") {
> $words = explode(' ',$string);
> if(count($words) >= $length) {
> $i = 0;
> $new = '';
> while($i < $length) {
> $new .= $words[$i].' ';
> $i++;
> }
> if($suffix) {
> $new .= $suffix;
> }
> return trim($new);
> } else {
> return $string;
> }
> }
>
> $foo = "This is my really long string";
>
> // EXAMPLES
>
> // no change, since $foo is less than 20 chars (default)
> echo chopper($foo);
>
> // echos 'This is my ...' -- uses default suffix
> echo chopper($foo,3);
>
> // echos 'This is my [too long]'
> echo chopper($foo,3,'[too long]');
> ?>
>
>
> Justin French
>
>
>
> on 19/02/03 10:18 AM, Michael P. Carel (mikecarel@teamglac.com) wrote:
>
> > it would be better if it will be chopped by words and not by characters.
Any
> > idea how?
> >
> > ----- Original Message -----
> > From: "Justin French" <justin@indent.com.au>
> > To: "Michael P. Carel" <mikecarel@teamglac.com>;
<php-general@lists.php.net>
> > Sent: Wednesday, February 19, 2003 7:26 AM
> > Subject: Re: [PHP] limiting characters
> >
> >
> >> Do you want it chopped at a certain number of words, or characters?
> >>
> >> Justin French
> >>
> >>
> >>
> >> on 19/02/03 10:00 AM, Michael P. Carel (mikecarel@teamglac.com) wrote:
> >>
> >>> Hi to all,
> >>>
> >>> How could i limit the character output that is being displayed in the
> > html
> >>> page. Is there a function or a php classes that perfectly support it?
> >>>
> >>> Example:
> >>>
> >>> $myoutput = "This is my sample output.";
> >>>
> >>> Required Output:
> >>>
> >>> This is my ....
> >>>
> >>> Any idea? Thanks in advance for the replies
> >>>
> >>>
> >>>
> >>> mike
> >>>
> >>>
> >
> > ---
> > [This E-mail scanned for viruses]
> >
> >