Quote:
Originally Posted by Killswitch
Yeah works perfect if it's just <a href="http://www.google.com">google</a> and not if it was <a rel="nofollow" href="http://www.google.com" title="google">google</a>
What I need it to do is find any a tag, with the specified href and anchor, ignores other attributes but returns true if the a tag has both the anchor and href
|
I know this is an old post but was doing something like this recently.
Code:
<?php
$content = file_get_contents('test.html');
$regex = "/<a.*? href=(\"|')(.*?)(\"|').*?>(.*?)<\/a>/i";
if (preg_match_all($regex,$content,$matches,PREG_SET_ORDER)) {
foreach ($matches as $match) {
// echo $match[0]; // full link including href
// echo $match[1]; // type of opening quote
// echo $match[2]; // url
// echo $match[3]; // type of closing quote
// echo $match[4]; // link text
}
}
?>
example urls that will work
Quote:
<a href="http://www.google.com" rel="external">google</a>
<a href='http://www.live.com' id="#links">links</a><br/><p></p>
<a class="links" href="http://www.google.com">google! google!</a>
|