对于preg_match用法:
<?php
// ...
$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;
});
// ...
报错
因为/ 斜线是特殊字符需要转义\/
$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;
});
https://github.com/mingzhanghui/urlGen/
https://www.php.net/manual/en/function.preg-match.php
preg_match ( string
$pattern
, string
$subject
[, array
&$matches
[, int
$flags
= 0 [, int
$offset
= 0 ]]] ) : int
array(4) {
[0]=>
string(2) "ac"
[1]=>
string(1) "a"
[2]=>
string(0) ""
[3]=>
string(1) "c"
}
array(4) {
[0]=>
string(2) "ac"
[1]=>
string(1) "a"
[2]=>
NULL
[3]=>
string(1) "c"
}