ankhmor Posted June 22, 2009 Share Posted June 22, 2009 I have a page of code. I'm using preg_match_all('/(<a href="){1}([a-zA-Z0-9:\/.?=]{1,})(">){1}/' ... to find all the links. However theres a line of code full of links which I actually need that seems to be not recognized by preg_match_all. its starts like this » <a href="[link]">[name of the link]</a><br> and just keeps repeating. The problem is I dont get any results the preg_match_all just seems to skip that line without matching it. Anyone has an idea on how to solve this. Link to comment https://forums.phpfreaks.com/topic/163188-solved-matching-text-from-a-string/ Share on other sites More sharing options...
nrg_alpha Posted June 22, 2009 Share Posted June 22, 2009 For stuff like this, you can use DOM / XPath instead of regex: Example: $dom = new DOMDocument; @$dom->loadHTMLFile('http://www.cs.sfu.ca/'); // replace url with site in question $xpath = new DOMXPath($dom); $aTag = $xpath->query('//a[@href]'); foreach ($aTag as $val) { echo '<span style="color: #A7AFB5">(' . $val->getAttribute('href') . ')</span> ' . $val->nodeValue . "<br /> "; } Link to comment https://forums.phpfreaks.com/topic/163188-solved-matching-text-from-a-string/#findComment-860994 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.