我有一个名为$trans
的多维数组,看起来像这样:
Array
(
[0] => Array
(
[0] => 1
[1] => Vol 19, No 2 (2018)
[2] => Africa Sanguine
[3] => https://www.ajol.info/index.php/asan/issue/view/17048
)
[1] => Array
(
[0] => 2
[1] => Vol 19, No 1 (2017)
[2] => Africa Sanguine
[3] => https://www.ajol.info/index.php/asan/issue/view/16693
)
)
我一直试图根据每个数组中的url提取元数据,并将其与每个数组的唯一ID匹配,在这种情况下,数组0的ID为1,数组1的ID为2。我已经成功提取了元数据,但是在将其插入到mysql表时,我遇到了一个问题,即为所有记录分配最后插入的数组的ID。例如,所有记录都分配了ID1。我该如何解决?
我用来获取元数据的代码看起来像这样
//create a multidemnsional array called $trans
array_unshift($citation, null);
$trans = call_user_func_array('array_map', $citation);
print_r($trans);
//loop through trans and get metadata for url found in $value3
foreach($trans as $key => $value){
//echo $value[3].'<br>';
$html2 = file_get_html($value[3]);
foreach($html2->find('table[class="tocArticle"]') as $div2) {
$DOM = new DOMDocument();
$DOM->loadHTML($div2);
$Detail = $DOM->getElementsByTagName('td');
$i = 0;
$j = 0;
foreach($Detail as $sNodeDetail) {
$aDataTableDetailHTML[$j][] = trim($sNodeDetail->textContent);
$j = $i % count($aDataTableDetailHTML[$j]) == 0 ? $j + 1 : $j;
}
}
}
print_r($aDataTableDetailHTML);