[英]PHP: Sending GET/POST with file_get_contents
I'm working on a new project. 我正在做一个新项目。 I route everything to router.php, but I have a problem now.
我将所有内容都路由到router.php,但是现在遇到了问题。 I'm using
keywords
, so I can use: 我正在使用
keywords
,因此可以使用:
<[DEFAULT_JS]>
<[DEFAULT_JS]>
And the return is: 返回的是:
<script src="./assets/js/jquery-1.11.0.min.js" type="text/javascript"></script>
This is the code: 这是代码:
// 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
You can see, I'm using file_get_contents to get the script and replace the 'keywords', but now it won`t send GET data with the page. 您可以看到,我正在使用file_get_contents来获取脚本并替换“关键字”,但是现在它不再与页面一起发送GET数据。 When I use include it should work but then I cannot use the 'keywords' anymore.
当我使用include时,它应该可以工作,但之后我将无法再使用“关键字”。
So, how can include a file and replace the keywords? 那么,如何包含文件并替换关键字呢?
So basically you are inventing some template system and you want to use PHP in your templates? 因此,基本上您是在发明一些模板系统,并且想在模板中使用PHP?
I think that you can use eval() function for that. 我认为您可以为此使用eval()函数。 But it's still not a good option.
但这仍然不是一个好选择。
// 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.