You're mere inches away from the answer -- you've already extracted the <a>
tags inside your foreach loop. You're grabbing all of them in a DOMNodeList, so each item in that list will be an instance of DOMElement, which has a method called getAttribute.
$a->item(0)->getAttribute('href')
will contain the string value of the href attribute. Tada!
It's possible that you might get an empty node list. You can work around this by checking that the first item in the list is an element.
$href = null;
$first_anchor_tag = $a->item(0);
if($first_anchor_tag instanceof DOMElement)
$href = $first_anchor_tag->getAttribute('href');