首页 > 解决方案 > 在 PHP 中将变量作为我的文件名会忽略句号

问题描述

这可能是一个简单的问题,但我有点挣扎。

$filename = $_GET['type'];
$data = file_get_contents($filename.json);

当我访问我的网站 www.site.com/report.php?type=1

我得到错误:

file_get_contents(1json): failed to open

为什么忽略句号给我一个错误的文件名(应该是1.json)

标签: php

解决方案


这是连接字符串的方式:

$data = file_get_contents($filename.".json");

推荐阅读