papaface Posted November 15, 2010 Share Posted November 15, 2010 Hey I am trying to find a way of retrieving the href value in a link on a specific webpage. However I only want to retrieve the href values for <a> elements that have the text "Click here to find out more". e.g. <a href="link.com/fdhh.php">Click here to find out more</a> Is there any specific PHP function that'll allow me to do that? Any help would be appreciated Link to comment https://forums.phpfreaks.com/topic/218765-find-href-values-for-specific-inner-value/ Share on other sites More sharing options...
ManiacDan Posted November 15, 2010 Share Posted November 15, 2010 Preg_match. Warning, you're about to learn regular expressions. It's a short trip from there to insanity. -Dan Link to comment https://forums.phpfreaks.com/topic/218765-find-href-values-for-specific-inner-value/#findComment-1134630 Share on other sites More sharing options...
Psycho Posted November 15, 2010 Share Posted November 15, 2010 $content file_get_contents('http://www.somedomain.com/somepage.php'); preg_match_all("#<a.*?href=\"([^\"]+)\"[^>]*>Click here to find out more</a>#", $content, $matches); print_r($matches[1]); Link to comment https://forums.phpfreaks.com/topic/218765-find-href-values-for-specific-inner-value/#findComment-1134634 Share on other sites More sharing options...
.josh Posted November 16, 2010 Share Posted November 16, 2010 suggestions for improvement: - make case insensitive - check if href attrib uses double OR single quotes - optional spacing between href=" (ex: href = " or href= " or href =") #<a[^>]*href\s?=\s?[\"']([^\"']+)[\"'][^>]*>Click here to find out more</a>#i Link to comment https://forums.phpfreaks.com/topic/218765-find-href-values-for-specific-inner-value/#findComment-1135077 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.