Immortal55 Posted September 25, 2006 Share Posted September 25, 2006 Alright, lets say I have a LONGTEXT field in my DB, and something long is entered in there. And on a page i only want to show......lets say 25 characters, how would I limit it to only showing 25 characters? Quote Link to comment Share on other sites More sharing options...
trq Posted September 25, 2006 Share Posted September 25, 2006 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. Quote Link to comment Share on other sites More sharing options...
tomfmason Posted September 25, 2006 Share Posted September 25, 2006 That is much better then what I was going to suggest.. I was going to say use str_split..Nice 1. Quote Link to comment Share on other sites More sharing options...
vbnullchar Posted September 25, 2006 Share Posted September 25, 2006 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... Quote Link to comment Share on other sites More sharing options...
Immortal55 Posted September 25, 2006 Author Share Posted September 25, 2006 Ah, awesome thanks a lot guys. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.