PHP code for link with text

maybe try with php DOMDocument rather than regex. I don’t think all DOMDocument methods will work with just an html fragment and not a complete document, but for your needs it may be enough:

<?php
$dom= new DOMDocument();
$html="<p>Some html with a <a href="http://foo.com/">link</a>. Some more text and <a href="http://bar.com/">another</a> link.</p>";
$dom->loadHTML( $html );
$dom->preserveWhiteSpace = false;
$elements = $dom->getElementsByTagName( 'a' );
foreach ( $elements as $element ){
    echo "link text: " . $element->nodeValue . "<br>";
    echo "href value: " . $element->getAttribute( 'href' ) . "<br><br>";
}

// outputs:
//
// link text: link
// href value: http://foo.com/
//
// link text: another
// href value: http://bar.com/