![](/img/trans.png)
[英]Using $_GET in PHP include with variable in the include URL
[英]How to include php variable url?
目前,作为示例,我在其中一个页面上有此php代码。
<?php include("codes/games/scripts/titles/angrybirds.php"); ?>
我将如何更改以使其可变:
$gametitle = "angrybirds";
像这样工作:
<?php include("codes/games/scripts/titles/$gametitle.php"); ?>
在此先感谢您的帮助!
自以来,该代码应按原样工作.
不会被解释为变量名称的一部分。 您可以在这里查看其输出: http : //codepad.org/ZbtiOPgB
但是,出于可读性考虑,我鼓励您使用明确的串联:
<?php include("codes/games/scripts/titles/".$gametitle.".php"); ?>
或将您的变量名称包装在{
和}
:
<?php include("codes/games/scripts/titles/{$gametitle}.php"); ?>
<?php include('codes/games/scripts/titles/'.$gametitle.'.php'); ?>
要么:
<?php include('codes/games/scripts/titles/'.$gametitle.'.php'); ?>
<?php
$file = 'codes/games/scripts/titles/' . $gametitle . '.php';
if (file_exists($file))
require_once($file);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.