简体   繁体   中英

Replacing php links to static links

I have script which uses absolute addressing in most areas, now I need to change them to relative addressing. But then the issue I am facing here is that, if for instance I have a website named

www.example.com
Now I want to change the links in php from

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

to

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

But I end up getting this result

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

I know something is wrong somewhere, but I still can't get it to work.. Any help with correct formatting will be highly appreciated. Sorry if my title for question is inappropriate.

Judging by the url setup:

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

This will split the url in pieces and picks the last item which is I think is the theme name you want.

Your $theme contains this url ' http://www.example.com/themes/in/ '. So if you just want the url to be like this

http://www.example.com/style.css instead of

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

then remove the $theme from the href section.

hope this helps

Their would be two possible solutions, either you remove the

http://www.example.com/   

from starting of <?php print $theme; ?> <?php print $theme; ?> OR only include theme name rather than with base bath.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM