search.php 567 B

1234567891011121314151617181920212223
  1. <?php
  2. //include 'kint.phar';
  3. function search($pattern, $str) {
  4. if (preg_match_all("/(?:[^\.]*)($pattern)(?:[^\.]*)/i", $str, $matches, PREG_PATTERN_ORDER) !== false) {
  5. //d($matches);
  6. foreach ($matches[0] as $index => $value) {
  7. $pattern_value = $matches[1][$index];
  8. echo str_replace($pattern_value, "<span style=\"background-color: yellow\">$pattern_value</span>", $value), "<br><br>";
  9. }
  10. }
  11. }
  12. if (empty($pattern = $_GET['q'])) {
  13. return;
  14. }
  15. $str = file_get_contents('regexp.txt');
  16. search($pattern, $str);