Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $filename = "a.txt";
- $example = file($filename, FILE_IGNORE_NEW_LINES);
- $words = "Emma Jefferson";
- $matches = array();
- foreach($example as $k => $v) {
- $fullStr = implode(' ', $words);
- if(preg_match("/\b$fullStr\b/i", $v))
- $matches[0][] = $v;
- $str = "";
- $i = 1;
- foreach($words as $word) {
- if ($str === "")
- $str = $word;
- else
- $str .= '|' . $word;
- if(preg_match("/\b$str\b/i", $v))
- $matches[$i][] = $v;
- $i++;
- }
- }
- $result = array();
- foreach($matches as $firstKey => $arr) {
- foreach($arr as $secondKey => $v) {
- $result[] = $v;
- }
- }
- $result = array_unique($result);
- foreach($result as $k => $v)
- echo $v . "<br>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement