Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. <?php
  2. $filename = "a.txt";
  3. $example = file($filename, FILE_IGNORE_NEW_LINES);
  4. $words = "Emma Jefferson";
  5. $matches = array();
  6. foreach($example as $k => $v) {
  7.     $fullStr = implode(' ', $words);
  8.     if(preg_match("/\b$fullStr\b/i", $v))
  9.         $matches[0][] = $v;
  10.     $str = "";
  11.     $i = 1;
  12.     foreach($words as $word) {
  13.         if ($str === "")
  14.             $str = $word;
  15.         else
  16.             $str .= '|' . $word;
  17.         if(preg_match("/\b$str\b/i", $v))
  18.             $matches[$i][] = $v;
  19.         $i++;
  20.     }
  21. }
  22. $result = array();
  23. foreach($matches as $firstKey => $arr) {
  24.     foreach($arr as $secondKey => $v) {
  25.         $result[] = $v;
  26.     }
  27. }
  28. $result = array_unique($result);
  29. foreach($result as $k => $v)
  30.     echo $v . "<br>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement