php - How to get part of text, string containing a phrase/word? -


i have database in mysql process php. in database have column long text. people search phrases search tool on website. displays items matching search.

now, question how part of text contains phrase search can see if it's looking for?

for example:

text: "this long text (...) problems jquery , other javascript frameworks (...) check out" 

and phrase jquery this:

about problems jquery , other javascript frameworks 

?

in mysql, can use combination of locate (or instr), , substring:

select substring(col, locate('jquery', col) - 20, 40) snippet yourtable 

this select 40 character snippet text, starting 20 characters before first occurrence of 'jquery'.

however, tends slow. alternatives worth looking into:

  • using similar method in php
  • using full-text search features mysql (not sure if of them help), or maybe whole separate full-text search engine solr.

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -