View Single Post
Old 08-07-2009, 04:04 AM   #1 (permalink)
russellharrower
The Contributor
 
russellharrower's Avatar
 
Join Date: Jul 2009
Posts: 80
Thanks: 13
russellharrower is on a distinguished road
Default Limit number of Words when fetching.

Hi,
I am using the following code to fetch data from the database. However while all the code works, one thing I can not figure out is how to make it so that for e.g

Say I have have the following text

Quote:
Editor’s note: The following report comes from Don Dodge, who blogs at Don Dodge on The Next Big Thing and is a business development executive for Microsoft. TechStarsis a startup incubator that selects 10 teams and provides funding of $18,000 per team, as well as free office space, operational support, and mentoring from investors, entrepreneurs and business leaders.
However when a user does a search for "business development" instead of showing from the word Editor's I want to show it from the word The Next Big Thing.

Is there any way to do that?

here is my code
Code:
<?php
	$position=300; // Define how many character you want to display.

  
		while($row = mysql_fetch_array($result))
		{
	
	$post = substr($message,$position,1); // Find what is the last character displaying. We find it by getting only last one character from your display message.

	if($post !=" "){ // In this step, if last character is not " "(space) do this step .

	// Find until we found that last character is " "(space) 
	// by $position+1 (14+1=15, 15+1=16 until we found " "(space) that mean character 20) 
	while($post !=" "){
	$i=1;
	$position=$position+$i;

	$post = substr($row['body'],$position,1); 
	}

	}

	$post = substr($row['body'],0,$position); // Display your message
	echo $post;
	echo "...";
	echo "<br/><br/>";
	}
	?>
russellharrower is offline  
Reply With Quote