Jump to content

Cutting off a sentence


XionX

Recommended Posts

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

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.