簡體   English   中英

將php鏈接替換為靜態鏈接

[英]Replacing php links to static links

我有在大多數區域使用絕對尋址的腳本,現在我需要將它們更改為相對尋址。 但是接下來我要面對的問題是,例如,如果我有一個名為

www.example.com
現在我想更改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" />

但是我最終得到了這個結果

 <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" /> 

我知道某處出了點問題,但仍然無法正常工作。任何有關正確格式的幫助將不勝感激。 抱歉,如果我的問題標題不正確。

通過url設置判斷:

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

這將把URL分成幾部分,並選擇最后一個項目,我認為這是您想要的主題名稱。

您的$theme包含此URL'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

希望這可以幫助

他們可能是兩種可能的解決方案,要么您刪除了

http://www.example.com/   

<?php print $theme; ?> <?php print $theme; ?>或僅包含主題名稱,而不包含基本名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM