onlyican Posted November 19, 2010 Share Posted November 19, 2010 Hi, I have a string which contains a mix of Content and anchor links Example: //Example $strContent = 'I am some <a href="/content.htm">Content</a> here, but I could have <a href="/link.php">a Link</a> <a href="http://www.example.com">Followed by another</a> Link, Mix external and not.'; I basically want to programatically pull out all of the Anchor links, and have an array of such Array('/content.htm', '/link.php', 'http://www.example.com'); Help me please. Got a brain freeze as its Friday Afternoon Link to comment https://forums.phpfreaks.com/topic/219203-get-all-links-from-a-string/ Share on other sites More sharing options...
ManiacDan Posted November 19, 2010 Share Posted November 19, 2010 preg_match_all Link to comment https://forums.phpfreaks.com/topic/219203-get-all-links-from-a-string/#findComment-1136680 Share on other sites More sharing options...
sasa Posted November 19, 2010 Share Posted November 19, 2010 <?php $strContent = 'I am some <a href="/content.htm">Content</a> here, but I could have <a href="/link.php">a Link</a> <a href="http://www.example.com">Followed by another</a> Link, Mix external and not.'; preg_match_all('~href=("|\')(.*?)\1~', $strContent, $out); print_r($out[2]); ?> Link to comment https://forums.phpfreaks.com/topic/219203-get-all-links-from-a-string/#findComment-1136788 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.