Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对php8.0+兼容有问题 #9

Open
Seagull-Y opened this issue Nov 13, 2024 · 0 comments
Open

对php8.0+兼容有问题 #9

Seagull-Y opened this issue Nov 13, 2024 · 0 comments

Comments

@Seagull-Y
Copy link

报错:
Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /www/wwwroot/xxxxxx.net/usr/plugins/TypechoCosPlugin/Plugin.php on line 559

问了下chatgpt,这一段改成这样就不报错了:

public static function refresh_cdn_url($opt, $cosClient, $text)
{
// 确保 $text 是一个字符串
$text = $text ?? '';

$text = preg_replace_callback(
    '/https?:\/\/[-A-Za-z0-9+&@#\/\%?=~_|!:,.;]+[-A-Za-z0-9+&@#\/\%=~_|]/i',
    function ($matches) use ($opt, $cosClient) {
        $url = $matches[0];
        if (strpos($url, self::getDomain()) !== false) {
            $expTime = explode('q-key-time%3D', $url);
            if (sizeof($expTime) > 1) {
                @$expTime = explode('%26q', $expTime[1])[0];
                @$expTime = explode('%3B', $expTime)[1];
                // 未过期,不更新
                if ($expTime > time()) {
                    return $url;
                }
            }
            $path = str_replace(self::getDomain(), '', $url);
            $url = $cosClient->getObjectUrl($opt->bucket, explode('?', $path)[0], '+10 minutes');
        }
        return $url;
    },
    $text
);
return $text;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant