1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Php File To Check For Text & Run Command

Discussion in 'PHP' started by ldigital, Feb 1, 2013.

  1. #1
    Hi,

    I am working on a PHP file and need it to open a URL and if there is a certain word or phrase on the web page then open a second URL. If the text is not there, then I need the first URL to continually open until the text is found.

    I would imagine this is pretty simple, something like an IF statement and a loop somewhere. But how do I do this?
    SEMrush
    Any help would be greatly appreciated! :)
     
    ldigital, Feb 1, 2013 IP
    SEMrush
  2. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #2
    $link = "www.example.com";
    $content = file_get_contents($link);
    $needle = "<div>find string</div>";
    if (strpos($content, $needle) === false) {
    header("Location: my_page.php");
    } else {
    echo "String found";
    }
    PHP:
    It may help you. Let me know.
     
    greatlogix, Feb 1, 2013 IP
  3. ldigital

    ldigital Active Member

    Messages:
    500
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #3
    Thanks for your response. I tried it - and it seems to load the 2nd page OK (my_page.php) but it doesn't seem to be loading it on the condition that it finds the "find string" text first, it just seems to run anyway?
     
    ldigital, Feb 1, 2013 IP
  4. ArMouR

    ArMouR Well-Known Member

    Messages:
    161
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    1
    #4
    ldigital mixed up the conditions a little, use the following:

    $link = "www.blahblah.com";
    $content = file_get_contents($link);
    $needle = "<div>find string</div>";
    if (strpos($content, $needle) === false) {
    //if it does not find the string, display the following
    echo "String found";
    } else {
    //else it found the string so proceed to the page
    header("Location: my_page.php");
    }

    Good luck! ;)
     
    ArMouR, Feb 1, 2013 IP
    nufcfan likes this.