Thanks for the reply chris, altho that was what I had already. Guess it's
down to me measuring chars myself then :-(
----- Original Message -----
From: "Chris Lee" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, August 13, 2001 10:28 PM
Subject: [PHP] Re: cropping a string


> function truncate($string, $size)
>  {
>   $new_string = substr($string, 0, $size);
>
>   $new_string = explode(' ', $new_string);
>   array_pop($new_string);
>   $new_string = implode(' ', $new_string);
>
>   return $new_string;
>  }
>
> this function can defn be improved apon.  all this does is trims the
string
> to the spec length and takes the last word (or pastial word) off.
>
> you might want to take a look at wordwrap() too, probably not what your
> looking for though.
>
> --
>
>   Chris Lee
>   [EMAIL PROTECTED]
>
>
>
> "Tom Carter" <[EMAIL PROTECTED]> wrote in message
> 01ea01c1243c$36fd1d40$0a00a8c0@bjorn">news:01ea01c1243c$36fd1d40$0a00a8c0@bjorn...
> > hi all
> >
> > I was wondering if anyone had found a solution to the problem of
cropping
> a
> > string to a certain length...however a certain length based upon the
> actual
> > "size" of it. By this I don't mean after n characters, or even after m
> words
> > (have a function for this already)... what I'm looking for is function
> that
> > will take a string and crop it down to a length dependant upon its size,
> ie.
> > it would treat a w different to a l (apologies to those reading this on
a
> > monospaced client). I'm guessing such a function would take type of font
> > (say, serif ot times) and the desired length in "standard" characters
and
> > then compare the string, translating each character into a length
> > comparative with the standard character.
> >
> > I appreciate tha because of the nature of the medium that it becomes
> > difficult to control how things appear on browsers, and that it would be
> > nigh on impossible to make an *exact* function, all I'm looking for is
> > something rough and ready which is better then counting chars.
> >
> > TIA, Tom
> >
>
>
>
> --
> 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]

Reply via email to