douba8819 2015-08-29 22:11
浏览 63
已采纳

如何在Mac上的本地PHP脚本中将文本文件导入为数组

I am running a local Applescript on my Mac that calls a php file to do some faster calculations. The php file has some arrays listed, like this:

$blackList = array(
'Bob Haskinson',
'Janet Vice',
'Howard Borderly',
)

I have a text file that's regularly generated with a list of names that I have to manually copy and paste into the PHP file each time it changes. This text file is already formatted like this:

'Bob Haskinson',
'Janet Vice',
'Howard Borderly',
'David Jadhurski',

I know how to use server side includes in a PHP page on a web server, and I know how to include a local file in an Applescript, but so far I can't get this example to work.

Based on the searches I made, I figured "file" would work. I found a lot of examples that pertain to Windows and Unix, and I double-checked how to write file paths on a Mac. I've tried the following (and several variants) but they all failed:

$blackList = file('/Users/derwood/Dropbox/Caps/Daily/Blacklist.txt');

$blackList = array('/Users/derwood/Dropbox/Caps/Daily/Blacklist.txt');

I haven't found anything pertaining to this situation in a few days of searching, but I may not be looking for the right keywords.

  • 写回答

1条回答 默认 最新

  • doubei3312 2015-08-30 10:49
    关注

    You need to write a function in php which collects the data from text file into array format in a php variable like this..

    $variable = file_get_contents('your text file');
    
    $data = explode(',',$variable);
    

    Now the $data will contain the array of data that can be used in your apple script.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!