I have a chunk of HTML code which I need to 'analyze'. It essentially contains a table of links. All I need to do is to extract the anchor text from each of the links and put them into an array. So consider the following (a few rows) I would need to be able to extract the words "link one", "link two" and "link three". There will of course be more rows than this in the final code. <td><a href="/link-to-a-page">link one</a></td> <td><a href="/link-to-notherpage">link two</a></td> <td><a href="/whatever-the-heck">link three</a></td> HTML: Any help would be much appreciated. Thanks
<?php $list = <<<list <td><a href="/link-to-a-page">link onea</a></td> <td><a href="/link-to-notherpage">link two</a></td> <td><a href="/whatever-the-heck">link three</a></td> list; preg_match_all('/<td><a href="(?<url>[^"]+)">(?<text>[^<]+)<\/a><\/td>/i', $list, $matches, PREG_SET_ORDER); var_dump($matches); PHP: