如何从多个文件访问内容 [英] How to access content from multiple files

查看:83
本文介绍了如何从多个文件访问内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以添加多个文件的内容,然后将合并的值放入一个文件中?

Is there any way that I can add the content of multiple files then put the combined values into one file?

我目前正在尝试:

 $start_tr = include 'include_all_items/item_input_start_tr.php' ;   
 $img_start = include 'include_all_items/item_input_img_start.php' ;
 $img_link = include 'include_all_items/item_input_img_link.php' ;
 $img_end = include 'include_all_items/item_input_img_end.php' ;

 $newcontent = "$start_tr
 $link 
 $img_start 
 $_POST[img_link] 
 $img_end ";

 $content = $newcontent.file_get_contents('../../include/item.computer.php');
 file_put_contents('../../include/item.computer.php', $content);

推荐答案

include 用于代码,而不用于 content .您必须使用 file_get_contents 来保存返回的值. include 不会赋予您该值.

include is for code, not for content. In your case you have to use file_get_contents so you can save the returned value. include will not give you that value.

include()

处理返回值:include失败时返回FALSE并发出警告.成功包含,除非被包含的文件覆盖,否则返回1.

Handling Returns: include returns FALSE on failure and raises a warning. Successful includes, unless overridden by the included file, return 1.

 $start_tr = file_get_contents('include_all_items/item_input_start_tr.php');   
 $img_start = file_get_contents('include_all_items/item_input_img_start.php');
 $img_link = file_get_contents('include_all_items/item_input_img_link.php');
 $img_end = file_get_contents('include_all_items/item_input_img_end.php');

现在,您可以像以前一样使用变量.

Now you can use your variable like you did.

 $newcontent = "$start_tr
 $link 
 $img_start 
 $_POST[img_link] 
 $img_end ";

这篇关于如何从多个文件访问内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆