基于变量(增量)分隔符将字符串拆分为多个数组

时间:2017-08-17 11:41:28

标签: php json wikipedia-api

我试图使用维基百科API将一些维基百科数据(表格)转换为html格式。我真的走得很远,觉得我已经接近尾声了(着名的遗言......) 但是,根据机场的排名将数据串转换为数组,我遇到了麻烦。数据吐出最繁忙机场的排名,我想根据排名将结果分成数组(所以First array =第一机场及其详细信息,第二机场=第二机场等等)。

代码:     

$endpoint = 'https://en.wikipedia.org/w/api.php?';

$worlds_busiest_airports_url = 'action=parse&page=List_of_busiest_airports_by_passenger_traffic&section=1&prop=wikitext&format=json';

$response = file_get_contents($endpoint . $worlds_busiest_airports_url);
$response_decoded = json_decode($response,true);

//echo "<pre>";
//print_r($response_decoded);
//echo "</pre>";

$data = $response_decoded['parse']['wikitext']['*'];

$start = strpos($data,'1.');

$data = substr($data,$start);

$strlen = strlen($data);

function index_data($data,$count,$strlen) {

    while ($count <= 19) {
        $count ++;
        $delimiter = $count . '.';


    }
}

index_data($data,0);

我有一个分隔符,每次达到正确的数字时都会递增。我只是不知道如何在这些分隔符之间获取字符并将它们转换为数组。我尝试过使用爆炸但最终还是返回了个别角色。

这是数据的格式(虽然显然有更多记录:

 1.|| {{flagicon|USA}} [[Hartsfield–Jackson Atlanta International 
Airport]]||[[Atlanta]], [[Georgia (U.S. state)|Georgia]]|| United 
States||ATL/KATL||104,171,935||{{steady}}||{{increase}}2.6%
|-
|2.|| {{flagicon|PRC}} [[Beijing Capital International Airport]]||[[Chaoyang 
District, Beijing|Chaoyang]]-[[Shunyi District|Shunyi]], [[Beijing]]|| 
China||PEK/ZBAA||94,393,454||{{steady}}||{{increase}}5.0%
|-

任何建议?我也试过循环,遍历字符串直到找到分隔符,但我再也不知道字符串的功能是否足以实现任何目的。

0 个答案:

没有答案