I need to extract the second URL from this string:
$string = '<td class="table_td"> submitted by <a href="https://www.example.com/account/user" target="_blank" rel="nofollow"> account </a> <br>
<a href="https://www.URL-I-NEED.com/BKHHZu_A4lu" target="_blank" rel="nofollow">[site]</a> <a href="https://www.example.com/settings/user/" target="_blank" rel="nofollow">[settings]</a></td>';
I tried this solution, and tried these settings:
$startTag = ' <a href="';
$endTag = '" target';
But it returned the first URL and not the one I need since those tags also appear before the substring I need.
I tried adding the <br>
before the newline to $startTag
, but it returned no string.
Basically, I need $startTag
needs to be {newline} <a href="
, but I can't figure out how to include that newline.
Or maybe I'm thinking about this wrongly, and there is a simpler way to do this by simply extracting all the URL's from that string, and then simply selecting the 2nd one.
Either way, how can I extract the 2nd URL in the string above?