View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

found search text - highlight and crop the result

Thread began 11/17/2009 4:26 am by office377308 | Last modified 11/18/2009 2:58 pm by office377308 | 1032 views | 5 replies

Jason ByrnesWebAssist

That would be a much more complex bit of code.


you could explode the string into an array, then loop through the array to find the search phrase then show it along with the word before or after. A very quick sample of the code for that would look like:

php:
<?php 

$searchPhrase 
"this is some stuff on my page, I hope you like it";
$searchTerm "stuff";
$searchIndex "";
$searchArray explode(" "$searchPhrase);
foreach(
$searchArray as $key  => $value) {
    if(
$value == $searchTerm$searchIndex $key;
}
echo(
$searchArray[$searchIndex-1]." <span style=\"color:red;\">".$searchArray[$searchIndex]."</span> ".$searchArray[$searchIndex+1]);
?>





of course, there are a number of scenarios this code does not account for, what if the search phrase is the first word? last word? it is meant as an example of one direction you could go.

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...