phpocean Posted June 10, 2009 Share Posted June 10, 2009 What I want is to have the numbers of characters to be displayed on my php page to be limited to 36 characters and for the last 3 characters to be displayed as ... telling my viewer that there is more but just not shown. Currently I am using this code and it solved 1 of my 3 problems. <?php print substr($list['title'], 0, 36); ?> This code limited the characters show on my page to 36. What i still want is: 1. Have ... be displayed on my page as the 3 last characters to tell my viewer there's more but not shown. i.e. 36characters... 2. The second issue I still have is not a big deal but would still be nice to have is how can I get < and > to count as two characters and not 8? FYI: < and > are just < and > symbols. I have try to tackles this issue for a while now and come to no solution, please help me out a little. Ocean Quote Link to comment https://forums.phpfreaks.com/topic/161676-solved-limit-characters-displayed-on-page-and-have-3-last-characters-be-displayed-as/ Share on other sites More sharing options...
Maq Posted June 10, 2009 Share Posted June 10, 2009 1. Use substr. Read the manual there are examples of this. 2. I thought I answered this in your last post, use html_entities_decode. Quote Link to comment https://forums.phpfreaks.com/topic/161676-solved-limit-characters-displayed-on-page-and-have-3-last-characters-be-displayed-as/#findComment-853091 Share on other sites More sharing options...
phpocean Posted June 10, 2009 Author Share Posted June 10, 2009 Ok I got the second part working now. I am currently studying the 1 part now... which involve having the last 3 characters as ... instead of their actual characters. Thank Maq, for the great services. Quote Link to comment https://forums.phpfreaks.com/topic/161676-solved-limit-characters-displayed-on-page-and-have-3-last-characters-be-displayed-as/#findComment-853160 Share on other sites More sharing options...
phpocean Posted June 10, 2009 Author Share Posted June 10, 2009 I red the substr() from php.net but don't find anything on cutting off long title and add ... to the end. Ok to refresh back, what I wanted is how can I make it that if the title is too long, it would cut it off at 36 characters and add ... to the end, noting that the title is too long to show all the words. <?php print substr($list['title'], 0, 36); ?> Quote Link to comment https://forums.phpfreaks.com/topic/161676-solved-limit-characters-displayed-on-page-and-have-3-last-characters-be-displayed-as/#findComment-853266 Share on other sites More sharing options...
Maq Posted June 10, 2009 Share Posted June 10, 2009 Try this: 36) ? substr($list['title'], 0, 36) . "..." : $list['title']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/161676-solved-limit-characters-displayed-on-page-and-have-3-last-characters-be-displayed-as/#findComment-853278 Share on other sites More sharing options...
phpocean Posted June 10, 2009 Author Share Posted June 10, 2009 Thank Maq. All is working now. Only one little problem, can you check my syntax here for me? <?php echo (substr(html_entity_decode($list['title'])))>36) ? substr(html_entity_decode($list['title']), 0, 31) . "..." : $list['title']; ?> using it without the html_entity_decode is good and in perfect condition but when I added html_entity_decode in, I must have done something wrong with the syntax as well. I'll try to solve it, but just thought I'll post it in case you can find the problem before I do. Quote Link to comment https://forums.phpfreaks.com/topic/161676-solved-limit-characters-displayed-on-page-and-have-3-last-characters-be-displayed-as/#findComment-853295 Share on other sites More sharing options...
Maq Posted June 10, 2009 Share Posted June 10, 2009 I think you have an extra parenthesis here (only need 2): ['title'])))>36) should be: ['title']))>36) Quote Link to comment https://forums.phpfreaks.com/topic/161676-solved-limit-characters-displayed-on-page-and-have-3-last-characters-be-displayed-as/#findComment-853298 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.