Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Max Characters Is X?
Amezis
post Dec 19 2005, 01:45 PM
Post #1


Privileged Member
*********

Group: Members
Posts: 535
Joined: 14-February 05
From: Oslo, Norway
Member No.: 3,759



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?
Go to the top of the page
 
+Quote Post
rvalkass
post Dec 19 2005, 02:00 PM
Post #2


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,153
Joined: 28-May 05
From: Devon, England
Member No.: 7,593
Spam Patrol



I haven't tested this, but it should work tongue.gif

CODE

$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!
Go to the top of the page
 
+Quote Post
Amezis
post Dec 19 2005, 03:04 PM
Post #3


Privileged Member
*********

Group: Members
Posts: 535
Joined: 14-February 05
From: Oslo, Norway
Member No.: 3,759



Thanks alot, it worked perfectly! biggrin.gif

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):

CODE
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 tongue.gif
Go to the top of the page
 
+Quote Post
electriic ink
post Dec 19 2005, 06:51 PM
Post #4


Incest is a game the whole family can play.
Group Icon

Group: [MODERATOR]
Posts: 1,223
Joined: 11-February 05
From: Heaven
Member No.: 3,709



Try:

CODE
if ($echo_text['post_subject'] > $max_length)
  {

  $titleattribute = ' title=\"' . $echo_text['post_subject']  . '\"';

  }
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Php Escaped Control Characters And Windows(3)
  2. Validation Script - Detecting Illegal Characters(0)
  3. Converting Textarea Return Characters To <br />(9)


 



- Lo-Fi Version Time is now: 11th October 2008 - 07:36 AM