XionX Posted July 4, 2007 Share Posted July 4, 2007 alright i have this code: <?php ConnectToforum(); $sql = "select * from `thread` where `forumid` = '48' order by `threadid` desc limit 0,30"; $query = mysql_query($sql); while ($row = mysql_fetch_array($query)) { echo "[<a href=\"forum/showthread.php?t=".$row['threadid']."\">View</a>] ".$row['title']." <br />"; "<p />"; } mysql_close(); ?> i want to know how to make a sentence it outputs to cut off and replace it with "..." after it extends the width of a table or after it exceeds a certain amount of characters. like if the sentence were this: "How now brown cow?" if it only allowed 10 characters to be shown it would output this: "How now..." so it would actually only show the first 7 characters of the sentence and then the last 3 would be "..." i'm fine with this being done by either a certain amount of characters or the width of the table, any help would be greatly appreciated, thanks Quote Link to comment Share on other sites More sharing options...
clanstyles Posted July 4, 2007 Share Posted July 4, 2007 You could use substr() and cut the string off after like 20 chacters. Quote Link to comment Share on other sites More sharing options...
XionX Posted July 4, 2007 Author Share Posted July 4, 2007 i'm still new to php so could you show me how to do that? Quote Link to comment Share on other sites More sharing options...
clanstyles Posted July 4, 2007 Share Posted July 4, 2007 <?php echo substr('abcdef', 1); // bcdef echo substr('abcdef', 1, 3); // bcd echo substr('abcdef', 0, 4); // abcd echo substr('abcdef', 0, ; // abcdef echo substr('abcdef', -1, 1); // f // Accessing single characters in a string // can also be achived using "curly braces" $string = 'abcdef'; echo $string{0}; // a echo $string{3}; // d echo $string{strlen($string)-1}; // f ?> http://us2.php.net/substr Quote Link to comment Share on other sites More sharing options...
warclown Posted July 4, 2007 Share Posted July 4, 2007 Im not quite sure what your looking for, but f.ex in my news script I use the MYSQL LEFT function. With this function you can predefine in the mysql query how many characters you want to extract from the row in MySQL. This works great when you want a "read more" function on f.ex your news. Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 4, 2007 Share Posted July 4, 2007 See here -> http://www.phpfreaks.com/forums/index.php/topic,147899.0/topicseen.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.