$html = @file_get_contents($urlw) or problem('Can\'t open Your Remote URL!');
$html = strtolower($html);
$site_url = strtolower($set['site_url']);


if (preg_match_all('/<a\s[^>]*href=([\"\']??)([^" >]*?)\\1([^>]*)>/siU', $html, $matches, PREG_SET_ORDER)) {
    foreach($matches as $match)
    {
        if ($match[2] == $set['site_url'] || $match[2] == $set['site_url'].'/')
        {
            $found = 1;
            if (strstr($match[3],'nofollow'))
            {
                $nofollow = 1;
            }
            break;
        }
    }
}

if ($found == 0)
{
    echo "<center><h2>Our URL Not FOund on your page please submit or check again</h2></center>";
}
else next processger...

in $html we getting the content of that page which that user give where he put our link
$site_url is the url of my site where he exchanging link
what is this actually this all code is doing 🤷
infact i was making a link exchange site where on a page people can submit their link for exchange and give their site link and the that page link where they have put our link
this code verify at the sPot did they have put our code or not

but m facing some problem.. beacuse it's not working good 🙁

    or tell me any function or method through that i can check my $site_url in $html in which m getting all the content of page
    😕

      Assuming a valid html page containing, anywhere on the page, these links

      <a href="http://yourdomain.example.com">Text</a>
      <a href="http://otherdomain.example.com">More text</a>
      <a href="relative_url">Internal link</a>
      

      And this script to check for your link, i.e. yourdomain.example.com

      $h = 'full contents from html page';
      $d = new DomDocument();
      $d->loadHTML($h);
      
      $x = new DOMXPath($d);
      $nodelist = $x->query('//a[@href="http://yourdomain.example.com"]');
      echo 'length: ' . $nodelist->length . '<br/>';
      if ($nodelist->length) {
      	foreach($nodelist as $n) {
      		echo $n->nodeValue . '<br/>';
      	}
      }
      

      Output

      length: 1
      Text
      

      So, all you need to do is check that for $nodelist->length (i.e. it is > 0).

      Edit: If you only wish to check a certain part of the url, you could of course use any of the relevant xpath functions such as

      //a[starts-with(@href,"http://yourdomain.example.com")]
      

        if i want to apply condition on next process that if there is really my url in his page then add his information my databse otherwise show a message where i put that condition

          well i don't know much about Object orient programing ....that's why u explain it simply that how can i put condition if url is available in that page got furthur otherwise show a mesaage

            This line is the conditional

            #success
            if ($nodelist->length) {
            
            }
            #failure
            else {
            
            }
            

              Or you could use Simple HTML DOM parser.

              As you can see, we discourage the use of regex to web-scrap.

              <?php
              
              // you include the downloaded file from sourceforge
              include('simple_html_dom.php');
              
              // make a new object
              $html = new simple_html_dom();
              
              // load that object with the page you want to search for links
              $html->load_file('http://www.site.com');
              
              // here we're searching for any link with their "href" attribute STARTING (^) with "http://yourdomain.example.com"
              // you could use $link->innertext
              foreach ($html->find('a[href^="http://yourdomain.example.com"]') as $link) {
                  echo $link->href . "<br />";
              }
              ?>
                nevvermind;10962451 wrote:

                Or you could use Simple HTML DOM parser.

                Never tried that one myself. Does it have any advantages? Else, why not use the dom extension?

                  @ - what can I say, I like jquery selectors.
                  This is about what are you most comfortable with.
                  There isn't any reason for not using dom.

                    well guyz stop discussing and thanks for help
                    i foound mistake in my first simple method and now that's working fine thanks for help

                      realcoder;10962588 wrote:

                      well guyz stop discussing and thanks for help

                      Why? 🙂)

                        realcoder;10962588 wrote:

                        well guyz stop discussing and thanks for help
                        i foound mistake in my first simple method and now that's working fine thanks for help

                        I don't even see it as off topic... It could actually affect the way you choose to solve your problem, and your threads may be beneficial to someone else as well; such as me, since I just learnt something new 🙂

                        nevvermind;10962582 wrote:

                        (...) jquery selectors.
                        This is about what are you most comfortable with.

                        Ah, of course. I was just curious.

                          Write a Reply...