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? Link to comment https://forums.phpfreaks.com/topic/21925-limit-shown-text/ 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. Link to comment https://forums.phpfreaks.com/topic/21925-limit-shown-text/#findComment-97971 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. Link to comment https://forums.phpfreaks.com/topic/21925-limit-shown-text/#findComment-97973 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... Link to comment https://forums.phpfreaks.com/topic/21925-limit-shown-text/#findComment-97981 Share on other sites More sharing options...
Immortal55 Posted September 25, 2006 Author Share Posted September 25, 2006 Ah, awesome thanks a lot guys. Link to comment https://forums.phpfreaks.com/topic/21925-limit-shown-text/#findComment-97989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.