<?php function truncateString($searchterm){ $string = 'Here is a sentence talking about blue. This sentence talks about red.'; $regex = '/.{0,10}\b' . $searchterm . '\b.{0,10}/si'; if (preg_match($regex, $string, $m)) { echo $m[0] . "\n"; } } truncateString('blue'); truncateString('red');
You have javascript disabled. You will not be able to edit any code.