Hi, just one correction to Kobus' code:

function myTruncate ($verylongstring, $length) {
  if (strlen($verylongstring) > $length) {
    $shorterstring = substr($verylongstring,0,$length-1) . "...";
  } else {
    $shorterstring = $verylongstring;
  }
  return $shorterstring;
}

He was missing a "{", otherwise it was fine.

--
Ben O'Neill


"Kobus Myburgh" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hi,

I have done a similar thing that worked reasonably well in Visual Basic
(however, included is a PHP snippet which might do the trick - I am not a
PHP pro).

write a small PHP function to select only a part of the string, say the
first 15 characters, and append "..." to the string, for example,

     thisisoneveryveryveryveryverylongword!!!!

will become:

     thisisoneveryver...

This is standard PHP string manipulation, which might look something like
this:


    function myTruncate ($verylongstring, $length) {
        if (strlen($verylongstring) > $length) {
            $shorterstring = substr($verylongstring,0,$length-1) . "...";
        }
        else
            $shorterstring = $verylongstring;
        }
        return $shorterstring;
    }


(This is untested, but should work...).

You can then call this in your table cell as follows:

<td>print myTruncate("thisisoneveryveryveryveryverylongword!!!!", 15);</td>

Hope this helps :)

Regards,

Kobus


>>> "Bobo Wieland" <[EMAIL PROTECTED]> 3/29/2003 12:37:02 PM >>>
When using dynamic content, like PHP interacting with MySQL it is easier to
use tables then anything else. But tables will get you into trouble! If
someone enters a really long word the tablecell will expand so that the
hwole word will be shown.

Is there some way I can prevent this? With html, php or css? I've tried
style='overflow:hidden' but it didn't work...



.bobo


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




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

Reply via email to