谈到A S preadsheet进入阵列和循环,并调用一个函数 [英] Turning a spreadsheet into array and loop and call a function

查看:188
本文介绍了谈到A S preadsheet进入阵列和循环,并调用一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是有关生成好友preSS组。

我有A S preadsheet(在这种情况下)组名,组描述和蛞蝓。

I have a spreadsheet with (in this case) a group name, group description and slug.

我要抓住从文件中的信息,把它变成一个数组,然后遍历并调用groups_create_group()每次。

I need to grab the information from the file, turn it into an array, then loop through it and call groups_create_group() every time.

我可以找到BP-groups.php该功能(http://www.nomorepasting.com/getpaste.php?pasteid=35217)。它告诉我,你需要填写的所有参数。

I can find that function in bp-groups.php (http://www.nomorepasting.com/getpaste.php?pasteid=35217). It tells me all the parameters you need to fill in.

我很新的这个和寻找我怎么能做到这一点。你知道我怎么能抓住这个信息,并把它变成一个数组?一个循环是通过并调用groups_create_group()每一次?

I'm quite new to this and looking for how I can do this. Do you know how I can grab this information and turn it into an array? An loop it through and call groups_create_group() every time?

如果您对此任何方便的链接,以及我将AP preciate它。

If you have any handy links regarding this as well I'll appreciate it.

推荐答案

只要你有可用的功能groups_create_group(即所需的文件已被包括在内),你应该能够做这样的事

As long as you have the function groups_create_group available (ie. The required file has been included) you should be able to do something like this

<?php

$groups = array();

if (($handle = fopen("groupData.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $group = array('group_id' => 'SOME ID', 'name' => $data[0], 'description' => $data[1], 'slug' => $data[2], 'date_created' => gmdate( "Y-m-d H:i:s" ), 'status' => 'public' );
        $groups[] = $group;
    }   
    fclose($handle);
}

foreach ($groups as $group) {
    groups_create_group($group);
} 

请注意,调用你提供的是显式调用其他方法将它传递给函数之前以消毒液塞粘贴code groups_create_group。所以,你可能希望将分配给 $组变量改成这样:

Note, the call to groups_create_group in the pasted code you provided was explicitly calling another method to sanitize the slug before passing it to the function. So you may want to change the assignment to the $group variable to this:

 $group = array('group_id'    => 'SOME ID', 
                'name'        => $data[0], 
                'description' => $data[1], 
                'slug' => groups_check_slug(sanitize_title(esc_attr($data[2]))), 
                'date_created' => gmdate( "Y-m-d H:i:s" ), 
                'status' => 'public' 
 );

这篇关于谈到A S preadsheet进入阵列和循环,并调用一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆