因为/ 斜线是特殊字符需要转义/
$url = $request->get('url'); $path = dirname(APP_PATH).'/data/monitor_hosts.txt'; $b = File::someRow($path, function($host) use ($url) { $pat = '/^http(s)?:\/\/'.$host.'.*$/'; preg_match($pat, $url, $matches); if ($matches) { return true; } return false; });