CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 Highlight search results

Print topic Send  topic

Author Message
Ron Borkent
Posted: 01/18/2002, 12:02 PM

My company has a 2 weekly newsletter. They are stored in the intranet database and thus available for reading via the company intranet. I've built this page with the possibility to search the articles with like %****% function. If a word is found in more then one article it can be a bit heavy on the eyes searching multiple newsletters for your search parameter.

At last the question:

Is there a way to make php highlight the search terms found in each newsletter?

Ron Borkent
Brent
Posted: 01/18/2002, 10:25 PM

Yes, it is fairly easy to do. If your text is a label, then make sure you
have HTML checked. In the Before Show event get the position of the search
word and insert the HTML string to highlight the word. So let's say the
word you're searching for is "Ohio" and it starts in position 100 of
$fldMyText. You would substring out the first 99 characters, insert "<B>", add
the search word "Ohio", end the HTML tag </B> and substring the rest of the
text. This gets assigned back to $fldMyText. Your search words will now appear
in bold. Instead of using your own loop, search, and substring commands,
most languages will have their own search and replace function like PHP's
$fldMyText=preg_replace($SearchWord,"<B>".$SearchWord."</B>",$fldMyText);

You can also use other HTML tags like font color etc..
Ron Borkent
Posted: 01/19/2002, 3:17 AM

OK, this is what I got
// putting the variable transfered by the search form into my own variable
$searchw=$pGriftb_text;
//Building the if statement to make sure the variable isnt empty
if($searchw != " ")
{
//printing the variable to check if the "if" statment works correct
//will remove this when the thing works
print("$searchw");

//the replacement
$fldGriftb_text=str_replace($searchw ,"<b>".$searchw ."</b>",$fldGriftb_text);
}

Ok now nothing happens. Everything works fine but the search variable does not get replaced. Any ideas?
Brent
Posted: 01/19/2002, 3:00 PM

<?
function HighlightText($TextIn, $SearchWord)
{
//Building the if statement to make sure the variable isnt empty
if($SearchWord != "")
{
//printing the variable to check if the "if" statment works correct
//will remove this when the thing works
print("\$SearchWord=$SearchWord<BR>Before: $TextIn<BR>");

//the replacement
$TextIn=str_replace($SearchWord, "<b>".$SearchWord ."</b>", $TextIn);
print("After: $fldGriftb_text");
}
return $TextIn;
}

print (HighlightText("This is the test sentence", "test"));
?>

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.