I've been searching for hours (there shouldn't be any duplicate) and tried many different ways using both regex (regular expressions) and DOMdocument without success.

**How the non-standard html code looks like:**

```
<a class="SOMECLASS" href="javascript:__FUNCTION(SOME_HREF_INSIDE)" onclick="SOME_JS_FUNCTION();" id="SOME_ID" style="SOME_STYLE">
    <a href="SOME_URL_3">SOME TEXT</a>
</a>

```

Now the problem is I'm trying to get the url "SOME\_URL\_3" and both when parsing using regex or DOMdocument, the pasing stops as soon as it encounters the first href. Of course as the second "a" tag is part of the first one, the parser only see it as one. 

**I observed that browsers seems to automatically separate the tags when parsing as follow:**

**Before:**

```
<a href="SOME_URL">
    <a href="SOME_URL_2">
    </a>
</a>

```

**After:**

```
<a href="SOME_URL">
</a>
<a href="SOME_URL_2">
</a>

```

I've not been able to replicate this browsers behavior using php.

**What I have tried that came closer to work:**

```
$dom = new DOMDocument();
@$dom->loadHTML($result);

foreach($dom->getElementsByTagName('a') as $link) { 
    $href_count = 0;
    $attrs = array();

    for ($i = 0; $i < $link->attributes->length; ++$i) {
        $node = $link->attributes->item($i);
        if ($node->nodeName == "href") {
            $attrs[$node->nodeName][$href_count] = $node->nodeValue;
            $href_count++;
            if ($href_count >= 2) {
                echo "A second href has been found";
            }
        }
    }

    echo "<pre>";
    var_dump($attrs);
    echo "</pre>";
}

```

As you may expect it unfortunately doesn't work, in that case I wouldn't be here asking for help...

Please don't hesitate to share your knowledge, any help or suggestion will be greatly appreciated!

---

**Update**
==========

I had forgotten to specify in my initial question that the answer should still allow to capture standard href. My goal is to "extend" or "improve" my actual html parser to ensure I'm also retrieving the urls from any href. My initial code was only using RegEx and I wasn't able to capture second href from nested "a" tags. A perfect answer would allow to capture both nested and standard href. Brandon White's solution is perfect for nested href only but it would be resource consuming to use two different RegEx (nested/standard) to parse the entire html content twice. An ideal solution would be a RegEx allowing to capture both at the same time, if this is possible.