View Single Post
Old 12-25-2009, 11:02 AM  
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,285
Quote:
Originally Posted by Killswitch View Post
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>
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote