English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

my php search program returns results in a list format, displaying the name and description of the rows that match the search string. Instead of displaying the ENTIRE description on the results page, I want to display the first line or so of the description.

Example:
What happens right now:

Search Results:

1 John Doe - John Doe is an outstanding man. Having a very generic name, he is well know and blah blah blah blah blah.
2. Jane Doe - Jane doe is an outstanding woman. Having a very generic name, she is well suited for her husband John.

What I'm trying to make happen:

Search Results:

1. John Doe - John Doe is an outstanding man.....
2. Jane Doe - Jane Doe is an outstanding wom.....

2006-09-30 00:41:43 · 4 answers · asked by detroitkid17 2 in Computers & Internet Programming & Design

4 answers

Write a new function to post-process the data....

function post_process_text($string, $threshhold)
{
if (strlen($string) > $threshhold)
{
/*
*Truncate at $thrshold
*/
$new_string = substr(0, $threshhold) . "...";
}
return $new_string;
}




You could get fancy and use strtok (or substr and strrchr) to look for a space and find the last space before the threshold and then substring so you dont have to chop a word in the middle

2006-09-30 01:06:41 · answer #1 · answered by Charlie 2 · 0 0

The "..." is a Truncated Link, found on many forum boards, I dont know much about how is it created but i have my own idea.

Step 1, Make a string variable.
Step 2, Push your search result in it (1 result).
Step 3, Make A Link to the Variable.
Step 4, Display the Variable's Link.

maybe you'll get my idea somehow.

2006-09-30 01:04:43 · answer #2 · answered by Rayne D 2 · 0 0

i don't comprehend a pair of issues. first of all, what's this code? in case you're invoking Hypertext Preprocessor, it may be

2016-12-12 17:50:05 · answer #3 · answered by dricketts 4 · 0 0

I'm writing this here without testing it, but the principle should work.

function getTrimmedString( $toTrim, $maxLength ) {

if( strlen( $toTrim ) < $maxLength ) {
return $toTrim; //not long enough to trim
}

return substr($toTrim,0,$maxLength) . "...";

}

If you're really smart, you could make the function wrap the trimmed string in a , with the TITLE attribute set to the whole string, and use the … entity instead of ... ( I didn't do that here because I don't know if you're doing other processing to the string that would break that )

2006-09-30 01:09:22 · answer #4 · answered by kirun 6 · 0 0

fedest.com, questions and answers