我有一系列Rackspace雲文件存儲的CDN URL,它們引用了一個HTTP地址,我希望將它們轉換爲HTTPS等效。將Rackspace Cloud文件轉換爲HTTP到HTTPS的CDN URL
Rackspace的雲文件CDN網址的格式如下:
http://c186397.r97.cf1.rackcdn.com/CloudFiles Akamai.pdf
而SSL相當於這個網址是:
https://c186397.ssl.cf1.rackcdn.com/CloudFiles Akamai.pdf
到的變化網址是(source):
- HTTP變得HTTPS
- 第二URI段(在該例子 'R97')變爲 'SSL'
在 'R00' 部分似乎在長度上變化(如一些是 'R6'等等),所以我無法將這些URL轉換爲HTTPS。這是我到目前爲止的代碼:
function rackspace_cloud_http_to_https($url)
{
//Replace the HTTP part with HTTPS
$url = str_replace("http", "https", $url, $count = 1);
//Get the position of the .r00 segment
$pos = strpos($url, '.r');
if ($pos === FALSE)
{
//Not present in the URL
return FALSE;
}
//Get the .r00 part to replace
$replace = substr($url, $pos, 4);
//Replace it with .ssl
$url = str_replace($replace, ".ssl", $url, $count = 1);
return $url;
}
但是,這對於第二個段的長度不同的URL無效。
任何想法讚賞。
剛剛經過測試,它適用於不同長度的零件。謝謝。 – 2012-03-26 16:46:01
乾杯,自從我把它寫下來以後,可能會有一些語法錯誤,但是很高興它可以工作! – jessica 2012-03-26 16:48:02