TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 08-07-2009, 04:04 AM   #1 (permalink)
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
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unique random number? code_junkie Advanced PHP Programming 4 12-21-2008 12:01 AM
Howto limit same results to one? marxx General 6 03-08-2008 06:50 PM
Version Checker khile Advanced PHP Programming 21 03-04-2008 10:08 PM


All times are GMT. The time now is 06:29 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design