Jump to content

Limit Shown Text


Immortal55

Recommended Posts

Best off doing it in your query. eg;

[code]
$sql = "SELECT SUBSTRING(fld,0,20) AS fldname";
[/code]

this would select the first 20 chars from the field called fld.

Of course you could also do it from within php using [url=http://php.net/substr]substr[/url], but there is no point selecting more data than you actually need.
Link to comment
Share on other sites

try this code

[code]function trunc($details,$max) {
if(strlen($details)>$max) {
        $details = substr($details,0,$max);
        $i = strrpos($details," ");
        $details = substr($details,0,$i);
        $details = $details."...";
    }
    return $details;
}[/code]

sample usage  echo trunc('abcdefghijklmnopqrstuvwxyz', 5);
outputs : abcde...
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.