dozpox8752 2013-08-18 11:08
浏览 34
已采纳

在脚本PHP中包含文件内容

Real simple one for someone. I've forgotten the terminology, so I'm having trouble finding a question I'm sure has already been answered.

I'd like to read the contents of a file that's included in the script itself eg.

<php
// NOTE: code is not correct, just illustrative.
// read 'file' data at end of script
$inlineFile = fopen(___FILE_HERE___,"r");
while ($rec = fgetcsv("\t", $inlineFile)) {
    // process file record
}
__FILE_HERE__
zzz 123 5445
aab 494 2983
__END_OF_FILE
?>

What is this technique officially called (eg. 'In-line data?') - if I know the term, I'll be off and away coding it I'm sure. UPDATE: I did find inline data eg.

$dutyCodesInline=<<<END
AL  Annual Leave    LEAVE_ANNUAL    LEAVE
BL  Long Service Leave  LEAVE_LSL   LEAVE
UW  Unworked Workers Comp.  LEAVE_OTHER LEAVE
END;

but my preference is to read the data as if it were a file (because one day it will probably be a file).

  • 写回答

1条回答 默认 最新

  • douwen4125 2013-08-18 15:18
    关注

    You cannot treat a part of a file like you wish to.

    You can use heredoc syntax for now, like this :

    $data = <<<END
    ...
    END;
    

    Later you replace this code by :

    $data = file_get_contents ( $filename );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并