繁体   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