从本地php文件获取URI,并将其包含在href标记内的另一个本地php文件中


Fetch URI from a local php file and include it in another local php file inside href tag

假设

我的css文件托管在https://cdn.domain.com/css/style.css

现在我的主站点是https://www.domain.com这里我有一个https://www.domain.com/scripts/source/link.php中的文件,它只包含cdn站点的URI:

A: https://cdn.domain.com/

现在,在我的索引文件中,我想包括css文件,但使用链接.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" />

那么,要实现CAb中应该有什么?

解决方案:

b部分中,

<?php
ob_start();
include "link.php";
$myvar = ob_get_contents();
ob_end_clean(); 
?>
<link rel="stylesheet" href="<? echo $myvar."style.css";?>" />