[英]PHP: Sending GET/POST with file_get_contents
我正在做一個新項目。 我將所有內容都路由到router.php,但是現在遇到了問題。 我正在使用keywords
,因此可以使用:
<[DEFAULT_JS]>
返回的是:
<script src="./assets/js/jquery-1.11.0.min.js" type="text/javascript"></script>
這是代碼:
// some code
if(in_array($_GET['p'], $allowedPages)) {
$source = file_get_contents('./pages/'.$allowedPages[$_GET['p']]);
foreach($keywords as $key => $value) {
$source = str_replace("<[".$key."]>", $value, $source);
}
echo $source;
} else {
// some code
您可以看到,我正在使用file_get_contents來獲取腳本並替換“關鍵字”,但是現在它不再與頁面一起發送GET數據。 當我使用include時,它應該可以工作,但之后我將無法再使用“關鍵字”。
那么,如何包含文件並替換關鍵字呢?
因此,基本上您是在發明一些模板系統,並且想在模板中使用PHP?
我認為您可以為此使用eval()函數。 但這仍然不是一個好選擇。
// some code
if(in_array($_GET['p'], $allowedPages)) {
$source = file_get_contents('./pages/'.$allowedPages[$_GET['p']]);
foreach($keywords as $key => $value) {
$source = str_replace("<[".$key."]>", $value, $source);
}
eval($source);
} else {
// some code
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.