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
https://forums.phpfreaks.com/topic/21925-limit-shown-text/#findComment-97971
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
https://forums.phpfreaks.com/topic/21925-limit-shown-text/#findComment-97981
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.