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 Quote Link to comment 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 Quote Link to comment 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]); Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.