mirror of
https://github.com/cedar2025/Xboard.git
synced 2025-01-22 10:38:14 -05:00
feat: 增加订阅地址支持[*-*]表达式
This commit is contained in:
parent
9192d5c11f
commit
c85ca31718
@ -111,7 +111,8 @@ class Helper
|
||||
public static function getSubscribeUrl($path)
|
||||
{
|
||||
$subscribeUrls = explode(',', admin_setting('subscribe_url'));
|
||||
$subscribeUrl = $subscribeUrls[rand(0, count($subscribeUrls) - 1)];
|
||||
$subscribeUrl = $subscribeUrls[array_rand($subscribeUrls)];
|
||||
$subscribeUrl = self::replaceRandomNumber($subscribeUrl);
|
||||
if ($subscribeUrl) return $subscribeUrl . $path;
|
||||
return url($path);
|
||||
}
|
||||
@ -126,4 +127,27 @@ class Helper
|
||||
$encoded = base64_encode($data);
|
||||
return str_replace(['+', '/', '='], ['-', '_', ''], $encoded);
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换字符串中的 [num1-num2] 格式为介于 num1 和 num2 之间的随机数字
|
||||
*
|
||||
* @param string $input 用户输入的字符串
|
||||
* @return string 替换后的字符串
|
||||
*/
|
||||
public static function replaceRandomNumber($input) {
|
||||
// 匹配 [1-4999] 格式的正则表达式
|
||||
$pattern = '/\[(\d+)-(\d+)\]/';
|
||||
|
||||
// 使用 preg_replace_callback 替换匹配到的内容
|
||||
$result = preg_replace_callback($pattern, function ($matches) {
|
||||
// 提取最小和最大值
|
||||
$min = intval($matches[1]);
|
||||
$max = intval($matches[2]);
|
||||
// 生成随机数
|
||||
$randomNumber = rand($min, $max);
|
||||
return $randomNumber;
|
||||
}, $input);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user