从php文件中接收变量使用fopen?

时间:2018-03-20 19:18:38

标签: php get fopen file-get-contents

我一直在开发博客系统,我希望从外部php文件中获取帖子标题和内容的信息,这是我的代码:

外部(博客文章的内容)文件: 03-20-2018-This-Is-A-Test.php

<?php
$Title = 'This is a test!';
$Date = '03-20-2018';
$Content = 'Blog Post&#39;s content!';
?>

查看博客帖子的客户端页面:发布Home.php

<?php
$Title = '';
$Date = '';
$Content = '';

$GetDate = $_GET['d'];
$GetTitle = $_GET['t'];

$postPath = "Posts/$GetDate"."-"."$GetTitle.php";

$postFile = fopen($postPath,"rt");
$postContent = fgets($postFile,filesize($postPath));
?>

<!--Some HTML-->

<h2><? echo $Title; ?></2>
<b><? echo $Date; ?></b>
<p><? echo $Content; ?></p>

<!--Some More HTML-->

<? fclose($postFile); ?>

客户的网页网址: example.com/Post%20Home.php?d=03-20-2018&t=This-Is-A-Test

重新格式化为: example.com/03-20-2018/This-Is-A-Test

如您所见,我正在使用GET参数来调用我希望从中收集信息的文件。 我尝试过使用 fopen ,但我无法上班。 include 也禁止使用我正在使用的特定服务器主机。

如果有人能帮助我开始工作,我愿意使用 file_get_contents

注意:我已确认我的主叫网址是正确的,我的php没有错误

所以,我正在尝试使用 fopen 从文件中收集 $ Title $ Date $ Content 的数据; 03-20-2018-This-Is-A-Test.php 并在客户端文件中使用该信息; 发布Home.php

1 个答案:

答案 0 :(得分:0)

我能够使用require()找到答案。