reciprocal link RE

Discussion in 'PHP' started by vixh, Oct 21, 2005.

  1. #1
    How do I write reciprocal link check regular expression?
    
    function isReciprocal() {
    		$page =$this->_fetchUrl('http://'.$this->backward_link);
    		$re="<a(.*)?href=\"http://(.*)?".$this->our_url."(.*)\"";
    		return preg_match(")$re)i", $page);
    	}
    
    PHP:
    But code above not works everywhere, couldnot check such links <a href='LINK'> etc.
    Maybe someones knows good RE?
     
    vixh, Oct 21, 2005 IP
  2. dpak

    dpak Peon

    Messages:
    111
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That regular expression looks like it should work... as long as $this->our_url doesn't contain http://. If you just want to be able to match single and double quotes, you could change it to this...

    $re="<a(.*)?href=[\"']?http://(.*)?".$this->our_url."(.*)[\"']?";
    PHP:
     
    dpak, Oct 21, 2005 IP
  3. michele

    michele Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Any reason why a simple ereg wont work here?

    
    function isReciprocal() {
       $page =$this->_fetchUrl('http://'.$this->backward_link);
       if (eregi($this->our_url,$page)) { return 1; }
       else { return 0; }
    } 
    
    PHP:
    ... or something like that.

    If fetchUrl() returns a string (I assume it does), maybe one of the substring type functions might also be useful.
     
    michele, Oct 21, 2005 IP