2016-06-13 60 views
-1

我工作的一个项目,以撕裂google.docs视频出在PHP重定向器,并把它们在videojs播放器(DOC因为目前的球员是在Flash)更改子域/域?

我到目前为止工作良好,但它撕裂链接出像这样

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

我想用PHP来代替整个域/子域以https:redirector.googlevideo.com/但保持一切后,像这样

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

我目前使用下面这行代替链接中的unicode,但我不知道如何去取代第一个域行。有任何想法吗? $ array =''','&'),$ cat [1]);

回答

0

我会用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