Amezis 0 Report post Posted December 19, 2005 I am currently making a code for my phpBB forum, where it will import the latest topics from a specific forum, and display it on the news section of my main page.But the width of that news section is very tiny, so I want the code to limit the numbers of characters to 25.So, let's say this is the full title:"This is the title which is a little too long so it needs to be shortened."This is what I want to show:"This is the title which ..."How can I do that? Share this post Link to post Share on other sites
rvalkass 5 Report post Posted December 19, 2005 I haven't tested this, but it should work $max_length = 25;$title = "This is the title which is a little too long so it needs to be shortened.";$title_length = strlen($title);if ($title_length > $max_length){ $title = substr_replace($title, '...', $max_length);}echo $title;It's pretty self explanitory. If you have any problems or it totally fails to work then feel free to ask! Share this post Link to post Share on other sites
Amezis 0 Report post Posted December 19, 2005 Thanks alot, it worked perfectly! But I have another question. If the title is too long, I want to add the title="fulltitlehere" attribute.So, basically, my topic title is "This is the title which is a little too long so it needs to be shortened". It is then shortened to "This is the title which ...". But if it is shortened, I want to have the title="" attribute in the link too:<a href="linktotopic" title="This is the title which is a little too long so it needs to be shortened">This is the title which ...</a>I tried with this code (using your code to define $max_length): if (($echo_text['post_subject']) > $max_length) { $titleattribute = ' title=\"' . ( $echo_text['post_subject'] ) . '\"' }$echo_text['post_subject'] is the complete topic title.Hope you understand what I need Share this post Link to post Share on other sites
electriic ink 1 Report post Posted December 19, 2005 Try: if ($echo_text['post_subject'] > $max_length) { $titleattribute = ' title=\"' . $echo_text['post_subject'] . '\"'; } Share this post Link to post Share on other sites