-1

How can I show only text around my sql search term?

For example if I have this text and my search term is bubbles:

Humans can see bubbles because they have a different refractive index (IR) than the surrounding substance. For example, the IR of air is approximately 1.0003 and the IR of water is approximately 1.333. Snell's Law describes how electromagnetic waves change direction at the interface between two mediums with different IR; thus bubbles can be identified from the accompanying refraction and internal reflection even though both the immersed and immersing mediums are transparent.

The above explanation only holds for bubbles of one medium submerged in another medium (e.g. bubbles of air in a soft drink); the volume of a membrane bubble (e.g. soap bubble) will not distort light very much, and one can only see a membrane bubble due to thin-film diffraction and reflection.

How do I output something like this (with bold)....

Humans can see bubbles because they have a different refractive index (IR) than ... thus bubbles can be identified from the accompanying refraction and internal reflection even though both the immersed and immersing mediums are transparent.

Robert
  • 25,425
  • 8
  • 67
  • 81
Ni Le
  • 201
  • 1
  • 3
  • 7
  • Not sure how much this has to do with MySQL, however I advise you look at [this](http://stackoverflow.com/questions/2757556/highlight-multiple-keywords-in-search) and [this](http://stackoverflow.com/questions/2292345/highlight-search-terms-in-php-without-breaking-anchor-tags-using-regex) – Kermit Aug 31 '12 at 21:54

2 Answers2

1

Here is an example. You get the text from your sql query into $text, but display after replacing keywords. See http://php.net/manual/en/function.preg-replace.php

$text = "Humans can see bubbles because..." ;
echo preg_replace("/bubbles/", "<b>bubbles</b>", $text);

Output:

Humans can see <b>bubbles</b> because...

BTW - I have no idea why S/O shows Humans in different color ;)

Grzegorz
  • 3,207
  • 3
  • 20
  • 43
0

you could use a set of INSTR, and SUBSTR to first find the term (using INSTR), then do a SUBSTR to the '.' character.

you will also need to be careful of the edge cases, like when there is no period, or you reach the beginning or end of the string etc.

Randy
  • 16,480
  • 1
  • 37
  • 55