fork download
  1. <?php
  2.  
  3. $string = 'abc\.com|xyz\.com';
  4. $s = "Some long string with http:". "//sub.abc.com inside";
  5. $res = preg_replace_callback('~http://\S+~', function ($m) use ($string) {
  6. if (preg_match('/\b(?:'.$string.')\b/', $m[0])) {
  7. return "GOOD_URL";
  8. } else {
  9. return "BAD_URL";
  10. }
  11. }, $s);
  12. echo $res;
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
Some long string with GOOD_URL inside