spikypunker Posted April 14, 2009 Share Posted April 14, 2009 how do i do it? Just simply take a variable from the Mysql, then before it's displayed on the page, limited to say, 15 characters? Thanks!¬ (i know i'm being dumb but cant figure it out) Quote Link to comment https://forums.phpfreaks.com/topic/154028-taking-a-variable-and-making-the-string-inside-it-no-longer-than-a-set-limit/ Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 try... <?php if(strlen($row['string']) > 15) { echo "string can not be that long!"; } else { echo $row['string']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/154028-taking-a-variable-and-making-the-string-inside-it-no-longer-than-a-set-limit/#findComment-809655 Share on other sites More sharing options...
spikypunker Posted April 14, 2009 Author Share Posted April 14, 2009 haha yeah thatd work, but you misunderstand. I need to take a string thats already in the DB and display it on the page, but only the first 15 characters. So i want it to trim the end of if the variable is longer than 15 characters! Quote Link to comment https://forums.phpfreaks.com/topic/154028-taking-a-variable-and-making-the-string-inside-it-no-longer-than-a-set-limit/#findComment-809681 Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 <?php echo trim(substr($row['string'],-15)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/154028-taking-a-variable-and-making-the-string-inside-it-no-longer-than-a-set-limit/#findComment-809690 Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 sorry that should be positive 16 not negative 15 <?php echo trim(substr($row['string'],16)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/154028-taking-a-variable-and-making-the-string-inside-it-no-longer-than-a-set-limit/#findComment-809723 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.