Seite 1 von 1

topic Titel nach zb 30 Buchstaben abschneiden

Verfasst: So 30.Jul, 2006 23:14
von Feuerball
Hallo,
wie kann ich hier bei den Themen titel die letzten Buchstaben abschneiden das dann zb ... steht ?

Ich eröffne ein neues Thema im Forum und als titel wähle ich
Das ist ein neues Thema
dieses sollte dann abgescnitten werde in zb
Das ist ein neues ...
aber das abschneiden sollte erst nach zb 30 buchstaben kommen.

Code: Alles auswählen

$sql = "SELECT t.topic_title, p.post_time
	FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
	LEFT JOIN " . FORUMS_TABLE . " f ON t.forum_id = f.forum_id
	WHERE p.post_id = t.topic_last_post_id
  	AND f.auth_view < 2
	ORDER BY t.topic_last_post_id DESC LIMIT 0,1";
	if ( !($result = $db->sql_query($sql)) )
	{
    message_die(GENERAL_ERROR, 'Could not obtain last topic data', '', __LINE__, __FILE__, $sql);
	}
	while ( $row = $db->sql_fetchrow($result))
	{
   $latest_topic = $row['topic_title'];
	}
	$db->sql_freeresult($result);

$image = "../images/signature.png"; 
$im = imagecreatefrompng($image); 
$tc  = ImageColorAllocate ($im, 176, 176, 176); 
$red  = ImageColorAllocate ($im, 225, 0, 0); 

$black  = ImageColorAllocate ($im, 0, 0, 0); 
$blue  = ImageColorAllocate ($im, 0, 102, 153); 


$total_users = get_db_stat('usercount'); 
$total_posts = get_db_stat('postcount'); 
$total_topics = get_db_stat('topiccount'); 
$j = strlen($total_users); 
$leerzeichen = $j*6+237; 

//
// hier mein versuch
// klappt aber nicht
// ich sehe nur ...
//
//	$j = strlen($total_users);
//	$leerzeichen = $j*6+237;
//	$j2 = strlen($latest_topic);
//	if (($j + $j2)>38)
//	{
//   $words = explode (" ", $latest_topic);
//   $text = '';
//   $latest_topic = '';
//   for($i=0;strlen($text) < (35 - $j);$i++)      {
//      $text = $text . $words[$i] . " ";
//      }
//   $latest_topic = str_replace($words[$i-1],"...",$text);
//	}
//////////////////////////////////////////////////

Verfasst: Mo 31.Jul, 2006 00:04
von oxpus
Warum so kompliziert?

Code: Alles auswählen

//
// hier mein versuch
// klappt aber nicht
// ich sehe nur ...
//
//   $j = strlen($total_users);
//   $leerzeichen = $j*6+237;
//   $j2 = strlen($latest_topic);
//   if (($j + $j2)>38)
//   {
//   $words = explode (" ", $latest_topic);
//   $text = '';
//   $latest_topic = '';
//   for($i=0;strlen($text) < (35 - $j);$i++)      {
//      $text = $text . $words[$i] . " ";
//      }
//   $latest_topic = str_replace($words[$i-1],"...",$text);
//   }
////////////////////////////////////////////////// 
So gehts viel einfacher:

Code: Alles auswählen

if (strlen($last_topic) > 30)
{
	$last_topic = substr($last_topic, 1, 27) . '...';
}

Verfasst: Mo 31.Jul, 2006 00:25
von Feuerball
warum so kompliziert, weil ich es nciht besser kannte.

aber das von dir klappt irgendwie nciht. Der schneidet nichts ab :/

im Anhang mal ein Bild wo es eigentlich abgeschnitten werden soll bei den Zahlen.

Die Zahlen habe ich im Forum als Themen titel gewählt und genau so wie auf dem Bild ist der titel :/

EDIT

Das klappt doch, ich mußte nur von deinem Code $last_topic in $latest_topic ändern.