2014-09-03 63 views
0

假设内的另一个本地php文件从本地php文件获取URI,包括它,在href标记

我的CSS文件中https://cdn.domain.com/css/style.css

主办现在我的主要部位是https://www.domain.com 这里我有一个文件在https://www.domain.com/scripts/source/link.php,它仅包含CDN网站的URI:

答:现在https://cdn.domain.com/

,在我的我ndex文件我想包括CSS文件,但使用link.php文件,如:

B:<link rel="stylesheet" href="<? include 'scripts/source/link.php'; ?>css/style.css" />

我知道前面的代码将无法正常工作像

C:<link rel="stylesheet" href="https://cdn.domain.com/css/style.css" />

所以实现ç,应在一个什么?

+0

所以你只是想'的https的内容:// www.domain.com /脚本/源/ link.php' ? http://stackoverflow.com/questions/1272228/how-do-i-load-a-php-file-into-a-variable回答你的问题? – Hirnhamster 2014-09-03 13:50:50

+0

如果link.php不包含“https:// cdn.domain.com /'B以外的任何内容,则应该可以工作。 – idmean 2014-09-03 13:59:31

+0

太棒了,它的工作。 – Mahir 2014-09-03 20:39:58

回答

0

解决方案:

在第

<?php 
ob_start(); 
include "link.php"; 
$myvar = ob_get_contents(); 
ob_end_clean(); 
?> 

<link rel="stylesheet" href="<? echo $myvar."style.css";?>" /> 
+0

顺便说一句:考虑使用'ob_start()'http://php.net/manual/en/function.ob-start.php – 2014-09-03 20:55:48