我正在尝试创建动态链接。从数据库中检索的$ path =“uploads /”和$ fileName =“Data Communication and Networking.pdf”。但是链接是用href =“upload / Data”创建的,忽略了“Communication and Networking.pdf”部分。如何在内容之间添加带空格的$ fileName。
$message=$row["message"];
$fileName=$row["filename"];
$date=$row["date"];
echo "<tr>";
echo "<td>".$Serial."</td>";
echo "<td>".$message."</td>";
echo "<td><a href=".$path.$fileName.">Download</a></td>";
echo "<td>".$date."</td>";
echo "</tr>";
$Serial++;;
答案 0 :(得分:2)
href
值必须包含在引号中。在您的值周围放置单引号。更改您的href
,如下所示:
echo "<td><a href='".$path.$fileName."'>Download</a></td>";
答案 1 :(得分:1)
您可以使用%20
$CompletePath = str_replace(" ", "%20", $path . $fileName);
echo "<td><a href=" . $CompletePath . ">Download</a></td>";
//uploads/Data%20Communication%20and%20Networking.pdf is a valid URL
答案 2 :(得分:0)
$path="/path";
$filename="/file with space.name";
echo "<td><a href=".$path.$fileName.">Download</a></td>";
将输出:
`<td><a href=/path/file with space.name>Download</a></td>`
所以你需要把引号放在引号之间:
$path="/path";
$filename="/file with space.name";
echo "<td><a href='".$path.$fileName."'>Download</a></td>";