所以我有这个功能
function parse_records($html) {
foreach($html->find('li.vcard') as $vcard):
$table = array();
foreach($vcard->find('span.given-name') as $given_name):
$table['given_name'] = (trim(addslashes($given_name->plaintext), " "));
endforeach;
foreach($vcard->find('span.family-name') as $family_name):
$table['family_name'] = (trim(addslashes($family_name->plaintext)," "));
endforeach;
foreach($vcard->find('span.location') as $location):
$table['location'] = (trim(addslashes($location->plaintext), " "));
endforeach;
foreach($vcard->find('span.industry') as $industry):
$table['industry'] = (trim(addslashes($industry->plaintext), " "));
endforeach;
foreach($vcard->find('dd.current-content') as $headline):
$table['headline'] = (trim(addslashes($headline->plaintext), " "));
endforeach;
foreach($vcard->find('a.btn-primary') as $url):
$table['url'] = addslashes($url->href);
endforeach;
return $table;
endforeach;
在我的主文件中,我像这样使用它。
$page = curl_request($fn, $ln);
$records = parse_records($page);
print_r($records);
但它仅适用于 1 条记录。我应该修改什么以便我可以传递正在传递的全部记录?我试过(trim(addslashes($given_name->plaintext), " "))
了,但没有用。