2013-03-29 157 views
1

我有腳本在絕大多數地區使用絕對地址,現在我需要將它們改爲相對地址。但後來我在這裏面臨的問題是,如果例如我有一個名爲替換php鏈接到靜態鏈接

www.example.com
網站現在我想從

<link href="<?php print $theme; ?>style.css" type="text/css" rel="stylesheet" /> 

<link href="<?php print $theme; ?>css/colorpicker.css" type="text/css" rel="stylesheet" /> 

改變PHP的鏈接

<link href="http://www.example.com/<?php print $theme; ?>style.css" type="text/css" rel="stylesheet" /> 

<link href="http://www.example.com/<?php print $theme; ?>css/colorpicker.css" type="text/css" rel="stylesheet" /> 

但我最終得到這個結果

<link href="http://www.example.com/http://www.example.com/themes/in/style.css" type="text/css" rel="stylesheet" /> 

<link href="http://www.example.com/http://www.example.com/themes/in/css/colorpicker.css" type="text/css" rel="stylesheet" /> 

我知道什麼是錯的地方,但我仍然無法得到它的工作。與正確的格式任何幫助將得到高度讚賞。對不起,如果我的題目是不恰當的。

+0

刪除''??php print $ theme; ?>'從你的鏈接代碼。 – Rikesh

+1

您應該檢查'$ theme'變量中的內容以及爲什麼 – Voitcus

+0

@Chris:請確保您沒有在「$ theme」vairbale中包含基本路徑? – Suleman

回答

0

他們的將是兩種可能的解決方案,要麼你從<?php print $theme; ?>開始刪除

http://www.example.com/ 

或僅包括 主題名稱,而不是用鹼浴。

1

來看由URL設置:

<?php 
$path = explode('/', $theme); 
$theme = end($path); 
?> 
<link href="http://www.example.com/themes/<?= $theme ?>/style.css" type="text/css" rel="stylesheet" /> 

這會分裂成幾部分URL,並挑選最後一個項目這是我覺得是你想要的主題名稱。

1

您的$theme包含此網址'http://www.example.com/themes/in/'。所以,如果你只是想要的網址是這樣

http://www.example.com/style.css而不是

http://www.example.com/http://www.example.com/themes/in/style.css

然後從href節中刪除$theme

希望這有助於