我会用preg_replace,这将替换字符串的一部分为https之间://和第一斜线:
$link = 'https://r8---sn-vgqs7n7k.c.docs.google.com/videoplayback?requiressl=yes&id=a8fa0f1624209c52&itag=22&source=webdrive&app=texmex&ip=2604:5800:0:35:250:56ff:fe9e:85f5&ipbits=32';
$link = preg_replace('#https://[^/]+#', 'https://redirector.googlevideo.com', $link);
echo $link;
输出:
https://redirector.googlevideo.com/videoplayback?requiressl=yes&id=a8fa0f1624209c52&itag=22&source=webdrive&app=texmex&ip=2604:5800:0:35:250:56ff:fe9e:85f5&ipbits=32
说明:
# : regex delimiter
https:// : literally https://
[^/]+ : one or more character that is not a slash
# : regex delimiter