PHP preg_match(): Unknown modifier ‘/'(PHP preg_ match(): Unknown modifier ‘/’)

因为/ 斜线是特殊字符需要转义/

$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;
});
 
————————

Because / slash is a special character, it needs to be escaped/

$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;
});