Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][HTML]Limit wyświetlanych znaków
Forum PHP.pl > Forum > Przedszkole
user1234
Cześć,
mam takie pytanko, czy można w HTML korzystając z jakiegoś atrybutu zrobić limit znaków,?
Mam pewien skrypt który pobiera tytuły tematów z bazy danych i wyświetla je na stronie, lecz wyświetla tytuły w pełnych znakach, a ja chce żeby wyświetlił tylko dziesięć znaków, a po dziesięciu znakach żeby były trzy kropki. smile.gif
Fifi209
Musisz sobie taki skrypt napisać ;-) HTML nie ma czegoś takiego.
user1234
A dodanie np. czegoś do kodu PHP
Tak wyglada ten kod:
  1. <?php
  2. /**
  3. *
  4. * @package phpBB Sidebar
  5. * @copyright (c) 2011
  6. * @license <a href="http://opensource.org/licenses/gpl-license.php" target="_blank">http://opensource.org/licenses/gpl-license.php</a> GNU Public License
  7. */
  8.  
  9. /**
  10. * @ignore
  11. */
  12. if (!defined('IN_PHPBB'))
  13. {
  14. }
  15.  
  16. /**
  17. * @package phpBB Sidebar - newest topics
  18. */
  19. class newest_topics
  20. {
  21. /*
  22. * basic variables:
  23. * $module_file - php file, language file and template file, php file must be in "includes/sidebar/", language file in "language/{$user->lang}/mods/sidebar/" and template file in "style/{$user->style}/templates/sidebar/"
  24. * $module_name - language name, please choose a distinct name, i.e. 'SIDEBAR_...', always has to be in capital letters
  25. * version - module version
  26. */
  27. var $module_file = 'newest_topics';
  28. var $module_name = 'SIDEBAR_NEWEST_TOPICS';
  29. var $version = '1.0.0';
  30.  
  31. /**
  32. * set this to false if you do not need any acp settings
  33. */
  34. var $load_acp_settings = true;
  35.  
  36. /**
  37. * module functions below
  38. */
  39. function load_module()
  40. {
  41. global $auth, $user, $db, $phpbb_root_path, $phpEx, $template, $config, $sidebar_config;
  42.  
  43. $user->add_lang('mods/sidebar/newest_topics');
  44.  
  45. $forum_array = array_unique(array_keys($auth->acl_getf('!f_read', true)));
  46.  
  47. $sql_and = '';
  48. if (sizeof($forum_array))
  49. {
  50. $sql_and = ' AND ' . $db->sql_in_set('t.forum_id', $forum_array, true);
  51. }
  52.  
  53. $sql_ary = array(
  54. 'SELECT' => 'u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, t.topic_id, t.forum_id, t.topic_title, t.topic_poster, t.topic_time, t.topic_first_poster_name, t.topic_first_poster_colour',
  55. 'FROM' => array(TOPICS_TABLE => 't'),
  56. 'LEFT_JOIN' => array(
  57. 'FROM' => array(USERS_TABLE => 'u'),
  58. 'ON' => 't.topic_poster = u.user_id',
  59. ),
  60. ),
  61. 'WHERE'=> 't.topic_approved = 1 AND t.topic_status <> ' . ITEM_MOVED . ' ' . $sql_and,
  62. 'ORDER_BY' => 't.topic_id DESC',
  63. );
  64.  
  65. $result = $db->sql_query_limit($db->sql_build_query('SELECT', $sql_ary), $sidebar_config['nt_per_page']);
  66. $is_row = false;
  67. while( $row = $db->sql_fetchrow($result) )
  68. {
  69. $is_row = true;
  70. $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']);
  71. $topic_title = censor_text($row['topic_title']);
  72. $sidebar_avatar = $row['user_avatar'] ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], ($row['user_avatar_width'] > $row['user_avatar_height']) ? 35 : (35 / $row['user_avatar_height']) * $row['user_avatar_width'], ($row['user_avatar_height'] > $row['user_avatar_width']) ? 35 : (35 / $row['user_avatar_width']) * $row['user_avatar_height']) : '';
  73.  
  74. $template->assign_block_vars('newest_topics',array(
  75. 'U_TOPIC' => $view_topic_url,
  76. 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  77. 'SIDEBAR_AVATAR' => $sidebar_avatar,
  78. 'S_DISPLAY_AVATARS' => ($sidebar_config['nt_avatars'] && $user->optionget('viewavatars')) ? true : false,
  79. 'U_VIEWPROFILE' => ($row['topic_poster'] != ANONYMOUS) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['topic_poster']) : '',
  80. 'TOPIC_TIME' => $user->format_date($row['topic_time']),
  81. 'TOPIC_TITLE' => $topic_title
  82. ));
  83. }
  84. $db->sql_freeresult($result);
  85.  
  86. if (!$is_row)
  87. {
  88. $template->assign_block_vars('newest_topics', array(
  89. 'NO_TOPICS' => $user->lang['SIDEBAR_NO_TOPICS'],
  90. ));
  91. }
  92. }
  93.  
  94. /**
  95. * acp frontend for the module
  96. * put the function in a comment or delete it if you don't need an acp frontend
  97. */
  98. function load_acp()
  99. {
  100. $display_vars = array(
  101. 'title' => 'SIDEBAR_NEWEST_TOPICS',
  102. 'vars' => array(
  103. 'legend1' => 'SETTINGS',
  104. 'nt_avatars' => array('lang' => 'ACP_NEWEST_TOPICS_AVATAR' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
  105. 'nt_per_page' => array('lang' => 'ACP_NEWEST_TOPICS_PER_PAGE', 'validate' => 'int:1', 'type' => 'text:3:4', 'explain' => false),
  106. )
  107. );
  108.  
  109. return $display_vars;
  110. }
  111.  
  112. /**
  113. * API functions
  114. */
  115. function add_config()
  116. {
  117. set_sidebar_config('nt_avatars', 1);
  118. set_sidebar_config('nt_per_page', 5);
  119. }
  120. }
  121.  
  122. ?>

Chodzi oczywiście o topic_title smile.gif
Substr
Zerknij na to http://kodcss.pl/przepelnienie,tekst,opis,text-overflow.html
user1234
To z tym HTML raczej sobie daruje, może wie ktoś jak w PHP to osiągnąć?

.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.