I'm trying to extract the limited words suppose 10 words before and after the search keyword.
I have done in following way but didn't get the desired result.
Code: Select all
<?php
$str ="PHP This reference covers PHP 4.3’s Perl-style regular expression support contained within the preg routines. PHP4 also provides POSIX-style regular expressions, but these do not offer additional benefit in power or speed. The preg routines use a Traditional NFA match engine. For an explanation of the rules behind an NFA engine, see “Introduction to Regexes and Pattern Matching.”";
$search = "PHP";
$reg_exp = "/[\w{,10}\.\s]*$search(\s)*[\w{,10}\'\"\.\s]*/im";
preg_match_all($reg_exp, $str, $match);
print_r($match);
?>Code: Select all
Array ( [0] => Array ( [0] => PHP This reference covers PHP 4.3 [1] => style regular expression support contained within the preg routines. PHP4 also provides POSIX ) [1] => Array ( [0] => [1] => ) )The pattern that I want is that it should extract the 10 words before and after the search keyword and the keyword to be highlighed.
Any help will be appreciated..
Thank you all.
Dibyendra