SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: scan a page..

  1. #1
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    273
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    scan a page..

    Hello guys

    a simple yet weird one.

    well i have a web page say 10 html files

    1 links to 2 2 linsk to 3 and so on.....9 links to 10

    ok?

    now i wanna write a script that reads html page 1, and if it finds a term xyz gives me the page link

    if it DOES not find the term xyz, it goes to the link and page 2.

    remmeber i dont know the page names so the script shud be able to read the link and go to that page 2

    cud u help me with this

    thanx
    ranjit

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your going to need to use php to read the html into a string
    simplest way is file_get_contents()

    then you can use strpos() or another string function to find if the term you want is in that page

    to find the other links on the page, you can use regular expressions, something like this. this should extract the href from any links

    PHP Code:
    <?php
    $subject 
    file_get_contents('the url goes here');
    $pattern '#<a.*?href\s*=\s*(["\'])?([^\\1]*?)\\1[^>]*?>[^<]*<\s*?/a\s*?>#si';

    preg_match_all($pattern$subject$matches);
    print_r($matches);


    ?>

  3. #3
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    273
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx mate


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •