ginerjm Posted November 3, 2021 Share Posted November 3, 2021 Ok - think I got it. This relies on always finding a period at the end of every sentence. $contents = "This is where cat is found. And it may be where cat is found a second time. And here it is the third occurrence of cat. Following the 3rd cat we have the 4th cat right here."; $sch_str = 'cat'; echo "Contents are:<br><br>"; echo "$contents<br><br>"; $last_start = 0; $last_end = 0; while ($pos = stripos($contents, $sch_str)) { // we have found the pos of the desired string // now locate the . prior to that pos $start = strrpos(substr($contents, 0, $pos), '.'); if (!$start) $start = 0; // now find the . following the current pos $end = stripos(substr($contents, $pos), '.') + $pos +1; // now output the sentence using start and end pos's echo "start $last_start, end " . ($last_end + $end) . " : " . substr($contents, $start, $end) . '<br>'; $contents = substr($contents, $end + 1); $last_start = $last_start + $end +1; $last_end = $last_end + $end +1; } Quote Link to comment https://forums.phpfreaks.com/topic/314158-using-a-readfile-value-as-a-variable/page/2/#findComment-1591736 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.