如何包含php变量url?

如何包含php变量url?,php,variables,include,Php,Variables,Include,目前,作为一个例子,我在我的一个页面上有这个php代码 <?php include("codes/games/scripts/titles/angrybirds.php"); ?> 像这样工作: <?php include("codes/games/scripts/titles/$gametitle.php"); ?> 提前感谢您的帮助 该代码应该按原样工作,因为不会被解释为变量名的一部分。您可以在此处看到它的输出: 但是,为了可读性,我建议您使用清晰的连接: &

目前,作为一个例子,我在我的一个页面上有这个php代码

<?php include("codes/games/scripts/titles/angrybirds.php"); ?>
像这样工作:

<?php include("codes/games/scripts/titles/$gametitle.php"); ?>


提前感谢您的帮助

该代码应该按原样工作,因为
不会被解释为变量名的一部分。您可以在此处看到它的输出:

但是,为了可读性,我建议您使用清晰的连接:

<?php include("codes/games/scripts/titles/".$gametitle.".php"); ?>

或:



我假设游戏标题是动态用户输入,这就是为什么我建议使用
file\u exists()
,这样如果游戏标题是假的,它就不会抛出错误。
<?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);
?>