I have a large buffer which I am finding a term in using $position=strpos($buffer,$term,$start);. I then want to extract the sentence containing the term and the next sentence. I am using
$begin=strrpos($buffer,". “,$position); to find the end of the previous sentence. It doesn’t seem to work. Am I doing the escape wrong? Is there another problem with it? Similar with using
$end=strpos($buffer,” “,$position+strlen($term); to find the end.
If I do not find a sentence, I want to take a fixed number of chars before and after the term, but not break in the middle of a word. Again, I am using
$realend=strrpos($buffer,” ",$endguess+1); It doesn’t seem to find the spaces that are there. I tried substituting “\s” for " “, but it didn’t make a difference. Similarly for
$realstart=strpos($buffer,” ",$startguess) +1; What am I doing wrong. What is the right usage for this?
I found my anwser at www.php.org in the commentary below strrpos. To search for a term backward from a position in the middle of a string, you have to write
$position= strrpos($buffer,$term,-(strlen($buffer)-$middle));
NOT
$position= strrpos($buffer,$term,$middle) as I had thought.
The documentation is not clear. Thank heavens for the comments!