Jump to content

[SOLVED] Limit characters displayed on page and have 3 last characters be displayed as...


Recommended Posts

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

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.

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); ?>

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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