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.

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

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀