Seek Text

I have some stings about 2000 words long and the positions of each word. Example “funny” is in position 13 (13th word from the start of the text)

What i need is to seek to the 13th word (funny) and show an extraction of around 15 words like a search engine does with a page

You can use regex as im only parsing 10 strings at a time

//**this is just an example, feel free to use your own method**//
$string = “I cant believe its not butter”;
$word_position = 3; //believe (already predetermined)
$seek_forward = 15; //how many words to move from 13th position
$seek_back = 5; //max words it will seek back without finding a capital character (see below)

//output : seek back to the start of the sentence aka the capital “I” so you will need to match an upper case letter before the word position and show 15 or so words after this
..I cant believe its not…

Leave a Reply

Your email address will not be published. Required fields are marked *