Need to get the 10 word before and 10 words after for the given text . i mean need to start the 10 words before the keyword and end with 10 word after the key word.
Given text : “Twenty-three”
The main trick : content having some html tags etc .. tags need to keep that tag with this content only . need to display the words from 10before – 10after
content is bellow :
removed
Thank you
This method assumes the words are only separated by spaces (not tabs, newlines or other whitespace) and is dependent upon the PHP library function “strip tags” which probably assumes well-formed HTML (which in my experience is a bad assumption).
untested but i believe it’s an effective approach
optionally, you can sterilize the whitespace: