Noskiw Posted November 3, 2009 Share Posted November 3, 2009 <?php $title = "Blog"; $connect = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("blog", $connect) or die(mysql_error()); function bbcode($string) { if ($string) { $bbcode_array = array('[b]', '[/b]', '[u]', '[/u]', '[i]', '[/i]', '[code]', ' ', '', ''); $bbcode_array_2 = array('<b>', '</b>', '<u>', '</u>', '<i>', '</i>', '<center><div style="width:90%;padding:3px;background-color:#000099;color:#FFFFFF;border:2px solid;">', '</div></center>', '<img src="', '">', '<img src="http://localhost/images/P.gif" />'); $new_string_2 = str_ireplace($bbcode_array, $bbcode_array_2, $string); return $new_string_2; } } echo "<h1>Blog</h1>\n"; $query = mysql_query("SELECT * FROM blog"); if (mysql_num_rows($query) == 0) { echo "<hr />There are no posts yet, make the first in the admin section!\n"; } else { while ($row = mysql_fetch_assoc($query)) { echo "<hr />"; $title2 = $row['title']; $name = $row['name']; $email = $row['email']; $post = $row['post']; $date = $row['date']; $time = $row['time']; echo "<h3>Title: " . $title2 . "</h3><table width='100%'><tr><td><b>Posted by: " . $name . "(" . $email . ") at " . $time . " on " . $date . "</b></td></tr><tr><td>" . nl2br(bbcode(strip_tags(wordwrap($post, 118, "<br />", true)))) . "</td></tr></table>\n"; } } echo "<hr />\n"; echo "Are you an admin? <a href='index.php?p=blog&p=credentials'>Place a post</a>\n"; ?>[/code] I want to limit "$post" to a certain amount of characters (say 200) and then say "... Read More" after it, but to be completely honest, I wouldn't know how to do it. I wish I did. Link to comment https://forums.phpfreaks.com/topic/180170-solved-need-to-limit-a-certain-amount-of-characters-on-display/ Share on other sites More sharing options...
mikesta707 Posted November 3, 2009 Share Posted November 3, 2009 $text = "some really long text"; $subText = substr($text, 0, 200); $subText .= (str_len($text) > 200) ? "... Read More" : ""; You should realize that this will cut off words too Link to comment https://forums.phpfreaks.com/topic/180170-solved-need-to-limit-a-certain-amount-of-characters-on-display/#findComment-950441 Share on other sites More sharing options...
Noskiw Posted November 3, 2009 Author Share Posted November 3, 2009 Sorry, I already figured it out, and yes I do realise that it will cut off words, thats what makes the reader/user go to the "...Read More" Section. Link to comment https://forums.phpfreaks.com/topic/180170-solved-need-to-limit-a-certain-amount-of-characters-on-display/#findComment-950452 Share on other sites More sharing options...
mikesta707 Posted November 3, 2009 Share Posted November 3, 2009 No i meant, it would cut words off in the middle. like long text is loooooooong might become: long text is looo... Read More. Not terrible, but just letting you know in case you didnt Link to comment https://forums.phpfreaks.com/topic/180170-solved-need-to-limit-a-certain-amount-of-characters-on-display/#findComment-950453 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.