如何在PHP中包含文件运行时

1 php include

我想包含不同的文件,具体取决于传递给get方法的参数.例如,如果id在URL中传递,101那么我想要包括file_101.php.这是我到目前为止:

if(cat_id == 101)
{
    $filename="file_101.php";
}

//some code here
include('$filename');
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

include('echo $filename;');
Run Code Online (Sandbox Code Playgroud)

但它给出了错误

include()[function.include]:无法访问echo $ filename;

Joh*_*nde 6

摆脱单引号.它们使PHP解析$为文字美元符号而不是变量名的开头.

include($filename);
Run Code Online (Sandbox Code Playgroud)