あなたが試すことができます
$html = file_get_html("http://xxxxxx/support/content-entry/create-anchor-tags/");
$anchor = array();
foreach ( $html->find("a") as $link ) {
if ($link->href === false) {
$key = $link->id ? $link->id : ($link->name ? $link->name : false);
if (! $key)
continue;
if (isset($anchor[$link->id])) {
$anchor[$link->id] = array_merge($anchor[$link->id], array("name" => $link->name,"id" => $link->id));
} else {
$anchor[$link->id] = array("name" => $link->name,"id" => $link->id);
}
} else {
if (strpos($link->href, "#") === 0) {
if (isset($anchor[substr($link->href, 1)])) {
$anchor[substr($link->href, 1)] = array_merge($anchor[substr($link->href, 1)], array("text" => $link->plaintext));
} else {
$anchor[substr($link->href, 1)] = array("text" => $link->plaintext);
}
}
}
}
var_dump($anchor);
出力
array
'id507d815fd9383' =>
array
'name' => string 'id507d815fd9383' (length=15)
'id' => string 'id507d815fd9383' (length=15)
'text' => string 'Visit the Useful Tips Section' (length=29)
'id507d815fd93a3' =>
array
'name' => string 'id507d815fd93a3' (length=15)
'id' => string 'id507d815fd93a3' (length=15)
'text' => string 'Visit the Useful Tips Section' (length=29)
'id507d815fd93bc' =>
array
'name' => string 'id507d815fd93bc' (length=15)
'id' => string 'id507d815fd93bc' (length=15)
'text' => string 'Visit the Useful Tips Section' (length=29)
'id507d815fd93d3' =>
array
'name' => string 'id507d815fd93d3' (length=15)
'id' => string 'id507d815fd93d3' (length=15)
'text' => string 'Visit the Useful Tips Section' (length=29)
'id507d815fd93eb' =>
array
'name' => string 'id507d815fd93eb' (length=15)
'id' => string 'id507d815fd93eb' (length=15)
'text' => string 'Visit the Useful Tips Section' (length=29)
'id507d815fd9404' =>
array
.......... so many more