Checking the presence of a link

Discussion in 'PHP' started by Darkhodge, Aug 30, 2006.

  1. #1
    Hey,


    I am creating a site and I need to be able to check the existence of a chunk of html coding on a specific url specified by a user.

    I'll have a table in a MySQL DB with the following information:

    ...userID.........URL............................activated
    ......1.............www. digitalpoint.com..........1......
    ......2.............www. msn.com...................1......

    etc...

    Obviously this is just an example.

    Anyway so I need a script to take each row, check the url for the existance of a chunk of html coding, and then update the activated field to the appropriate value - 1 if the code is there, 0 if not.

    I was wondering if someone could give me advice or tell me a good resource to learn how to do this.


    Thanks :)

    Hodge
     
    Darkhodge, Aug 30, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You would need to loop through the table one line at a time. For each line you then use fopen on the url and then use the following to detect if the string exists.
    ?php
    $mystring = 'abc';
    $findme  = 'a';
    $pos = strpos($mystring, $findme);
    
    // Note our use of ===.  Simply == would not work as expected
    // because the position of 'a' was the 0th (first) character.
    if ($pos === false) {
       echo "The string '$findme' was not found in the string '$mystring'";
    } else {
       echo "The string '$findme' was found in the string '$mystring'";
       echo " and exists at position $pos";
    }
    ?>
    PHP:
    Now you can update the DB with 1 or 0 as appropriate.
     
    mad4, Aug 31, 2006 IP
  3. Darkhodge

    Darkhodge Well-Known Member

    Messages:
    2,111
    Likes Received:
    76
    Best Answers:
    1
    Trophy Points:
    185
    #3
    Thanks for that :)

    Just to clarify is $mystring= fopen( URL FROM DB ) and $findme the piece of coding I want to find on that page?
     
    Darkhodge, Aug 31, 2006 IP
  4. surefire

    surefire Guest

    Messages:
    40
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Go to sourceforge.net and look for a class called Snoopy. The short Readme file will show you exactly how to grab all the links from a webpage and stuff them into an array. This, plus some simple code to run through your database, should be all you need.
     
    surefire, Sep 1, 2006 IP
  5. Darkhodge

    Darkhodge Well-Known Member

    Messages:
    2,111
    Likes Received:
    76
    Best Answers:
    1
    Trophy Points:
    185
    #5
    Awesome I'll check that out once I get to that stage :)
     
    Darkhodge, Sep 1, 2006 IP