gpt4 book ai didi

php - 从 file_get_contents() 值创建数组

转载 作者:可可西里 更新时间:2023-10-31 22:52:14 24 4
gpt4 key购买 nike

socallink.txt:

"Facebook","Twitter","Twitter","google-plus","youtube","pinterest","instagram"

PHP:

$file = file_get_contents('./Temp/socallink.txt', true);
$a1 = array($file);
print_r($a1);

结果:

Array
(
[0] => "Facebook","Twitter","Twitter","google-plus","youtube","pinterest","instagram"
)

需要:

$a1['0']=facebook;
$a1['1']=Twitter;

最佳答案

这解决了你的问题:

$file = '"Facebook","Twitter","Twitter","googleplus","youtube","pinterest","instagram"'; // This is your file

首先去掉所有的".

$file = str_replace('"', '', $file);

然后在每 , 爆炸

$array = explode(',',$file);

var_dump($array) 给出:

array(7) {
[0]=>
string(8) "Facebook"
[1]=>
string(7) "Twitter"
[2]=>
string(7) "Twitter"
[3]=>
string(11) "google-plus"
[4]=>
string(7) "youtube"
[5]=>
string(9) "pinterest"
[6]=>
string(9) "instagram"
}

全局代码如下:

$file = file_get_contents('./Temp/socallink.txt', true);
$file = str_replace('"', '', $file);
$a1 = explode(',',$file);

希望对你有帮助

关于php - 从 file_get_contents() 值创建数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37213674/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com