Is it possible to parse an HTML file in PHP to extract all <a href tags and save them in a two-dimensional array?
To parse an HTML file in PHP and extract all <a href> tags, you can use the PHP Simple HTML DOM Parser library. This library allows you to easily manipulate HTML elements using jQuery-like syntax. You can loop through all <a> tags in the HTML file, extract the href attribute, and save them in a two-dimensional array.
<?php
include('simple_html_dom.php');
$html = file_get_html('example.html');
$links = array();
foreach($html->find('a') as $element){
$link = array(
'href' => $element->href,
'text' => $element->plaintext
);
$links[] = $link;
}
print_r($links);
?>