Counting number of links on a page

Discussion in 'PHP' started by kinggomez, Mar 21, 2010.

  1. #1
    I am trying to count the number of links on a page. That is every link, internal, external etc. I have been trying but cant seem to figure it out. I already have the box where I can input the URL of the page I want to check but cant get the result.

    Does anyone know how to solve this?
     
    kinggomez, Mar 21, 2010 IP
  2. Lordo

    Lordo Well-Known Member

    Messages:
    2,082
    Likes Received:
    58
    Best Answers:
    0
    Trophy Points:
    190
    #2
    You will need to do the following:
    1. file_get_contents of the URL
    2. preg_match_all to extract the links on the page (using a proper link regex)
    3. get the count of links
     
    Lordo, Mar 21, 2010 IP
  3. kinggomez

    kinggomez Active Member

    Messages:
    268
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Thanks for the reply. I dont suppose you know where I can find an exmaple of similar code?
     
    kinggomez, Mar 21, 2010 IP
  4. Lordo

    Lordo Well-Known Member

    Messages:
    2,082
    Likes Received:
    58
    Best Answers:
    0
    Trophy Points:
    190
    #4
    You can do it bit by bit.
    I mean you will easily find examples for every step I mentioned even on php.net itself.
     
    Lordo, Mar 21, 2010 IP
  5. kinggomez

    kinggomez Active Member

    Messages:
    268
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #5
    OK cool I will take a look. Thanks
     
    kinggomez, Mar 21, 2010 IP
  6. LookAtHerBeautifulFace

    LookAtHerBeautifulFace Peon

    Messages:
    171
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Last edited: Mar 21, 2010
    LookAtHerBeautifulFace, Mar 21, 2010 IP
  7. kinggomez

    kinggomez Active Member

    Messages:
    268
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #7
    kinggomez, Mar 21, 2010 IP
  8. kinggomez

    kinggomez Active Member

    Messages:
    268
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #8
    OK problem solved :)
     
    kinggomez, Mar 21, 2010 IP