douba8819 2015-08-29 14: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 02: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部