<?php
$chunk = 'This is a very large text line I have ever seen in my life and I love it.';
$searchfor = 'I have';
$pattern = preg_quote($searchfor, '/');
$pattern = "/^.*?(.{1,10}$pattern.{1,10}).*$/m";
if(preg_match_all($pattern, $chunk, $matches)){
echo "Found matches:\n";
echo implode("\n", $matches[1]) . "\n";
}
$searchfor = 'a very';
$pattern = preg_quote($searchfor, '/');
$pattern = "/^.*?(.{1,10}$pattern.{1,10}).*$/m";
if(preg_match_all($pattern, $chunk, $matches)){
echo "Found matches:\n";
echo implode("\n", $matches[1]) . "\n";
}
$searchfor = 'and I';
$pattern = preg_quote($searchfor, '/');
$pattern = "/^.*?(.{1,10}$pattern.{1,10}).*$/m";
if(preg_match_all($pattern, $chunk, $matches)){
echo "Found matches:\n";
echo implode("\n", $matches[1]) . "\n";
}
preferences:
27.58 ms | 406 KiB | 5 Q