Preg_match_all() 将结果放入关联数组
Preg_match_all() put results in associative array
正如标题所说,无论如何都要做到这一点:
$leagueoflegendswebsite = file_get_contents($_POST['leagueoflegendswebsite']);
preg_match_all('/{{ci\|([^\|||}]+)/', $leagueoflegendschampions, $champion);
$leagueoflegendschampions
只是$leagueoflegendswebsite
的一部分。
var_dump()
: http://i.imgur.com/UgMDQj8.png
有没有办法让它像$champion['Sona']
、$champion['Blitzcrank']
、$champion['Fiddlestick']
等等?
根据您的 matches 数组,使用 array_combine():
$champion = array_combine($champion[1], $champion[0]);
或者要获得默认值,请填写键:
$champion = array_fill_keys($champion[1], ''); // or use some value other than ''
或者翻转它:
$champion = array_flip($champion[1]);
正如标题所说,无论如何都要做到这一点:
$leagueoflegendswebsite = file_get_contents($_POST['leagueoflegendswebsite']);
preg_match_all('/{{ci\|([^\|||}]+)/', $leagueoflegendschampions, $champion);
$leagueoflegendschampions
只是$leagueoflegendswebsite
的一部分。
var_dump()
: http://i.imgur.com/UgMDQj8.png
有没有办法让它像$champion['Sona']
、$champion['Blitzcrank']
、$champion['Fiddlestick']
等等?
根据您的 matches 数组,使用 array_combine():
$champion = array_combine($champion[1], $champion[0]);
或者要获得默认值,请填写键:
$champion = array_fill_keys($champion[1], ''); // or use some value other than ''
或者翻转它:
$champion = array_flip($champion[1]);