[ create a new paste ] login | about

Link: http://codepad.org/Xm2YHddx    [ raw code | output | fork ]

PHP, pasted on Oct 12:
1
2
3
4
5
6
7
8
9
10
11
12
<?php

$phrase = "Welcome to Stack Overflow! Visit your user page to set your name and email.";
$keyword = "Visit";
$lcWords = preg_split("/\s/", strtolower($phrase));
$words = preg_split("/\s/", $phrase);
$wordCount = 5;

$position = array_search(strtolower($keyword), $lcWords);
$indexBegin =  max(array($position - $wordCount, 0));
$len = min(array(count($words), $position - $indexBegin + $wordCount + 1));
echo join(" ", array_slice($words, $indexBegin, $len));


Output:
1
Welcome to Stack Overflow! Visit your user page to set


Create a new paste based on this one


Comments: