External links

Discussion in 'PHP' started by jasvo, Aug 24, 2010.

  1. #1
    Could somebody help me? I`m looking for script to count number of external links in site. I try google, but I didn`t find right solution. Thanx.
     
    jasvo, Aug 24, 2010 IP
  2. andymoo

    andymoo Peon

    Messages:
    169
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Easy enough to code, file_get_contents explode the hrefs and count how many elements are in the array would be my starting point
     
    andymoo, Aug 24, 2010 IP
  3. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #3
    s_ruben, Aug 24, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    In PHP you'd fetch the contents of the page (file_get_contents), grab all urls within href tags (preg_match), then loop through (foreach) all the urls, counting all the urls found (count) which do not equal the url of the page (!= operator) being fetched.

    Theirs probably other ways of doing this (such as with DOM), but this is possibly the most popular.
     
    danx10, Aug 24, 2010 IP