OK I need help, why wont the this work ?
On the bannerswarm site there is a link marketleap and for some reason it doesnt find it. I also tried with fopen and fread
No matter what I try that link is not being found on that site..

Anyone have some good ideas why not ?

if (strpos(file_get_contents("http://www.marketleap.com/publinkpop/"),
"http://www.bannerswarm.com/purchase.html")!==false) {
// I'm linked
echo "found";
}else{
// I'm not linked
echo "nope";
}

    That's because it's not there.....

    Use Firefox, open the first URL (marketleap.com) and hit Ctrl+F (Edit --> Find in this Page...)
    Type in "banners" and it's nowhere on the page.

    Sorry....

      Not checking maretleeps site for a link, were checking the banner site for a marketleep link..

        Thank You
        Now how can I do that same thing with adding preg_match so that it actually looks for the a tag and http://
        If you can help

          <?php
          $cont = file_get_contents('http://www.bannerswarm.com/purchase.html');
          
          $pattern = "/<a.*href=\"http\:\/\/www\.?marketleap\.com\/publinkpop\/\"[^>]*>.*<\/a>/si";
          
          if(preg_match($pattern, $cont))
            echo 'Linked!!';
          else
            echo 'Not Linked.';
          ?>

          That works for me....

            if (preg_match('#<a(.*?)href="http://www.marketleap.com/publinkpop/"(.*?)>(.*?)</a>#si', file_get_contents('http://www.marketleap.com/publinkpop/'))) 
            {
            // I'm linked
            echo "Found!";
            }
            else
            {
            // I'm not linked
            echo "Not found...";
            }

            There you go. 🙂

              Haha!!! I'm faster 🙂

              I even had to install a local server to test upon!! :p 🙂

              And either will do... they're all the same....

              Even eregi is fine....

                bpat1434 wrote:

                Haha!!! I'm faster 🙂

                I even had to install a local server to test upon!! :p 🙂

                And either will do... they're all the same....

                Even eregi is fine....

                Actually I see a problem in yours...you need to replace . with .? 😛

                  No, no I don't because the .* means 0 or more.... so if it's not there.... the 0 will cover it.... so it's fine.

                    bpat1434 wrote:

                    No, no I don't because the .* means 0 or more.... so if it's not there.... the 0 will cover it.... so it's fine.

                    In case you didn't know, regular experssions are "greedy," meaning they take as much as they can. So if you had two links like that...let's say you had this:

                    <a target="_BLANK" href="http://www.marketleap.com/publinkpop/">Link</a><br />
                    <a target="_BLANK" href="http://www.marketleap.com/publinkpop/">Another Link</a>

                    In the first .* PHP would match this:

                     target="_BLANK" href="http://www.marketleap.com/publinkpop/">Link</a><br />
                    <a target="_BLANK" 

                    This is because PHP will try to take as much as possible, but the ? makes it "ungreedy."

                      huh.... learn something new every day....

                      THanks for pointing it out to me... 😉

                        If I use a url that does not exist I get this error :
                        Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known

                        How can I use this :

                        if (strpos(file_get_contents("$siteurl"),
                        "$recip")!==false) {
                        echo "Link Exist":
                        } else {
                        echo "Link Does Not Exist";
                        }
                        

                        So that it works more like this :

                        if (strpos(file_get_contents("$siteurl"),
                        "$recip")!==false) {
                        echo "Link Exist":
                        } else {
                        echo "Link Does Not Exist";
                        } else {
                        echo "Name or service for $siteurl not known ";
                        }
                        
                          if(($conts = file_get_contents($siteurl)) != FALSE)
                          {
                            if(strpos($conts, $recip) !== FALSE)
                            {
                              echo 'Link Exists';
                            }
                            else
                            {
                              echo 'Link Does Not Exist';
                            }
                          }
                          else
                          {
                            echo 'Name or service for '.$siteurl.' not known.';
                          }

                          Something like that....

                            If file_get_contents() failed you can reasonably conclude that the URI used does not exist.

                              If file_get_contents fails, it will give you a warning with a description of the error.

                              You cannot determine that a web page contains a link to your site simply because it contains your URL. You are not parsing the HTML properly- it could be inside an HTML comment or something else.

                              The only way to determine that there is a link there is to parse the HTML properly and find it. Otherwise, the page author could easily do something which would fool your code.

                              Mark

                                yes but if file_get_contents() failed , I dont want to show error, would rather show something else...

                                Other problem :

                                Also with the above code, how would I parse the HTML properly and find the link. So that a page author isnt trying to fool the code and put link between comment tags or something.

                                  With this code, I still see the error, and I do see the echo.
                                  Echo is good, but do not want to show error.
                                  I am actually getting 2 Warnings.
                                  getaddrinfo failed: Name or service not known
                                  And
                                  failed to open stream: Permission denied

                                  And both are because the site does not exist..

                                  if(($conts = file_get_contents($siteurl)) != FALSE) 
                                  { 
                                    if(strpos($conts, $recip) !== FALSE) 
                                    { 
                                      echo 'Link Exists'; 
                                    } 
                                    else 
                                    { 
                                      echo 'Link Does Not Exist'; 
                                    } 
                                  } 
                                  else 
                                  { 
                                    echo 'Name or service for '.$siteurl.' not known.'; 
                                  }